收藏
回答

wx.scanQRCode调用失败webview为什么会调用onShow?

function callScan() {
    console.log("调用扫码", wx.scanQRCode);
    // 调用扫码
    wx.scanQRCode({
      needResult: 1, // 默认为0,扫描结果由微信处理,1则直接返回扫描结果,
      scanType: ["qrCode"], // 可以指定扫二维码还是一维码,默认二者都有
      success: function (res) {
        var result = res.resultStr; // 当needResult 为 1 时,扫码返回的结果
        console.log("扫码结果", result);
      },
      fail: function (res) {
        console.log("扫码失败", res);
      },
    });
  }

在网页中使用如上方法调用微信扫码 调用失败后 页面刷新了 导致页面刷新后 点击返回页面会再刷新一下 相当于页面刷新之后向页面栈推了一个页面

onShow() {
      console.log('是否登录isLogin', this.isLogin, this.url)
      if (this.isLogin) {
        wx.login({
          success: (res) => {
            if (res.code) {
              console.log(
                '登录成功!',
                res.code,
                this.loadUrl + '?authCode=' + res.code
              )
              this.url = this.loadUrl+'?authCode=' + res.code
              uni.hideLoading()
            } else {
              console.log('登录失败!' + res.errMsg)
            }
          },
        })
      } else {
        console.log('未登录,直接跳转', this.loadUrl + '?time=' + Date.now())
        this.url = this.loadUrl
        uni.hideLoading()
      }
    },
回答关注问题邀请回答
收藏

2 个回答

  • 社区技术运营专员--许涛
    社区技术运营专员--许涛
    03-04

    03-04
    有用
    回复
  • 智能回答 智能回答 本次回答由AI生成
    03-03
    有用 1
    回复 1
    • Mr. Li
      Mr. Li
      03-03
      因为页面直接刷新了 扫码失败的日志也被刷掉了 我临时将 页面src赋值改为在onload中赋值 得到的错误日志是{errMsg: scanQRCode:permission denied}
      03-03
      回复
登录 后发表内容