扫描二维码及条形码,获取结算后跳转到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客户端。