解决办法是进入当前页面不要使用router进入使用window.location.href进入当前页面
比方说现在有a和b两个页面,
从a页面跳转到b页面使用window.location.href跳转
在b页面中有方法需要调用扫码,function () {wx.scanQRCode…}
//a页面 只要是跳转到b页面跳转就用window.location.href
methods:{
btnClick(){
window.location.href = '/b' //跳转到b页面
}
}
//b页面
methods:{
scanQrCode() {
let that = this
wx.scanQRCode({
// 默认为0,扫描结果由微信处理,1则直接返回扫描结果,
needResult: 1,
scanType: ['qrCode'],
success(res) {
// res.resultStr 拿到返回的结果
console.log(res.resultStr.split('=')[1])
that.getStock(res.resultStr.split('=')[1]) //继续执行其他
}
})
},
}