1、UniApp开发openRobot基础一:扫描二维码

扫描二维码及条形码,获取结算后跳转到scanResult页
<template>
    <view class="container">
        
        <view class="intro">本项目开发的功能</view>
        <text class="intro">详见:</text>
        <!-- <uni-link :href="href" :text="href"></uni-link> -->
        <button @tap="openExternalLink">打开外部链接</button>        
        <view class="list_item" @tap="goScanCode">扫一扫</view>
    </view>
</template>

<script>
    export default {
        data() {
            return {
                href: ''
            }
        },
        methods: {
            openExternalLink(){
                this.href='http://gc.mysum.com';
                // #ifdef H5
                window.open(this.href, "_blank"); // "_blank"表示在新窗口或新标签页中打开链接
                // #endif
                // #ifdef APP-PLUS || MP-WEIXIN
                plus.runtime.openURL(this.href, '_blank', {
                    system: true // 在系统浏览器中打开(可选)
                });                
                // #endif
            },
            goScanCode(){                        
                uni.scanCode({
                    success: res => {                                        
                        uni.navigateTo({
                            url: '/pages/scanResult/scanResult?item=' + encodeURIComponent(res.result)                    
                        });                    
                    }
                });
            }            
        }
    }
</script>

<style>
    .container {
        max-width: 960px;
        min-width: 320px;
        margin: 0 auto;
        padding: 20px;
        font-size: 18px;
        line-height: 36px;
    }
</style>

扫码识别到的内容,在scanResult页显示,如果是网页则打开:
<template>
    <view class="container">
        <view class="item">
            <view class="item-first">
                <view>                    
                    <view>扫码识别到的内容</view>
                </view>                
            </view>
            <view class="item-second" @tap="goUrl">{{scanResult}}</view>
        </view>
        <view class="btn">
            <button type="primary" @tap="goBack">返回</button>
        </view>
    </view>
</template>

<script>
    export default {
        data() {
            return {
                scanResult: ''
            }
        },
        onLoad(option) {
            this.scanResult = decodeURIComponent(option.item);
        },
        methods: {            
            goUrl(){                    
                plus.runtime.openWeb(this.scanResult);                 
            },
            goBack(){
                uni.navigateBack();
            }
        }
    }
</script>

<style>
    .container{
        max-width: 960px;
        min-width: 320px;
        margin: 0 auto;            
    }    
</style>

通过本文的介绍,我们已经学习了扫码与跳转网页。源码下载地址:https://download.youkuaiyun.com/download/cacheer/90228202
下一篇将开发tcp与udp客户端。
 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值