因为前段时间camera组件出现扫码框看不见,以及在ios上无法用定位样式,所以改用wx.scanCode模拟连续扫码。扫码成功后调用wx.redirectTo跳回本页面,在线下可以做到,在线上连扫5次都没有就没反应了。
手机型号:小米mix2
微信版本号:7.0.15
基础库:2.11.1
以下是测试代码:
wxml:
<button bindtap="clickScanCode">扫码</button>
js:
onLoad: function (options) {
if (options.isOpen == "true") {
this.clickScanCode();
let hello = this.data.hello;
hello = options.hello.split(",");
this.setData({
hello: hello
})
}
},
clickScanCode: function () {
wx.scanCode({
onlyFromCamera: false,
scanType: "barCode",
success: (res) => {
let hello = this.data.hello;
hello.push(res.result);
this.setData({
hello: hello
})
wx.redirectTo({
url: "/pages/test?isOpen=true&&hello=" + hello
})
},
fail: (res) => {
if(res.errMsg == "scanCode:fail cancel"){}
}
})
}