微信js-sdk扫一扫,在单应用里面还没有扫描二维码就自动执行扫描的回调了

需求:点击分享按钮,弹出需要扫描进行分享的二维码,调用微信js-sdk里面的二维码扫描功能。

代码:

<a  class="bottom-send-btn bottom-btn-preview"  id="bottom-send-btn" @click="sendArticle">
            分享
        </a>
        
        
  sendArticle(){
            this.isShowQRCode = true;
            const _this = this;
            const target_url = `http://192.168.0.102:8787/#/article/${this.realarticleId}`;
            $('#qr-code-center').html('');//避免重复生成二维码
            $('#qr-code-center').qrcode({width: 180,height: 180,text: target_url});
            wx.scanQRCode({
              needResult: 0, // 默认为0,扫描结果由微信处理,1则直接返回扫描结果,
              scanType: ["qrCode"], // 可以指定扫二维码还是一维码,默认二者都有
              success: function (res) {
                var result = res.resultStr; // 当needResult 为 1 时,扫码返回的结果
                console.log("result:aaaaaaa",result);
                //                    window.location.href = result;//因为我这边是扫描后有个链接,然后跳转到该页面
                sendShareArticle(`v1/tool/users/${localStorage.getItem("userId")}/wechatArticleShares/`,{
                  article_id:_this.realarticleId
                }).then((res)=>{

                },(err)=>{

                })
              }
            });
        },       

发现当点击这个分享按钮的时候,二维码扫描就回到了success(都还没有进行扫描),感觉很奇怪啊,正确的应该是扫描完后才回调。

图片:
图片描述

哪位大神帮忙解答下

阅读 6.5k
1 个回答

solved by myself

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题