xx.js
getScancode: function () {
var _this = this;
wx.scanCode({
success: (res) => {
var result = res.result;
console.log("获取二维码信息成功:"+res.result); // 打印出扫描结果
_this.setData({
result: result,
})
},
fail:function(res) {
console.log("获取二维码信息失败: "+res.result);
}
})
},
xx.wxml
<view>
<button bindtap='getScancode'>扫一扫</button>
<view wx:if="{{result !=''}}">
<view>扫码的内容:{{result}}</view>
</view>
</view>