vue调用微信JSDK 扫一扫,相册等需要注意的事项

2022-07-25,,,,

在vue里面需要注意的第一个问题就是路由得设置成

第二个就是 跳转路由的时候

不要用this.$router.push 或者this.$router.replace  前者在ios 和安卓端都调不起来的

后者只能在安卓端有效 在ios端无效

this.$router.push的效果图

测试工具上是可以调起,然后在安卓手机上和ios上这个是调不起的

这个在测试上椰是可以的,然后在安卓端上可以,在ios上会出现无效的token 40029

config:function(res){  //配置jssdk和调取扫一扫功能
     // location.reload();
     this.isdisable = true;
     this.model = 'block'; 
     settimeout(() => {
     this.isdisable = false;
      var that = this,
      user = json.parse(sessionstorage.getitem('user')),
      iscode = json.parse(sessionstorage.getitem('key')),
      dizhi = encodeuricomponent(location.href.split('#')[0]);
      console.log(dizhi);
     var data = {
      dizhi:dizhi,
      i:user.uniacid,
      token:user.token
     }
      this.$fetch('app/index.php/?c=entry&a=wxapp&do=write&m=mzhk_sun&calltest=?&',data)
     .then((res)=>{
      console.log(res)
       that.model = 'none';
       
      wx.config({
        debug : false, // true为开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
        appid : res.appid, // 必填,公众号的唯一标识
        timestamp : res.timestamp, // 必填,生成签名的时间戳
        noncestr : res.noncestr, // 必填,生成签名的随机串
        signature : res.signature,// 必填,签名
        jsapilist : ['checkjsapi', 'startrecord', 'stoprecord','translatevoice','scanqrcode', 'opencard'] // 必填,需要使用的js接口列表,所有js接口列表见附录2

      });
       // 初始化
       wx.ready(function(){
         wx.scanqrcode({
           needresult: 1, // 默认为0,扫描结果由微信处理,1则直接返回扫描结果
           scantype: ["qrcode","barcode"],
           success:((option)=>{
             var o = json.parse(option.resultstr);
             var id = o.id;
             var ordertype = o.ordertype;
             var user_id = o.user_id
             that.id = id;
             that.ordertype = ordertype;
             that.user_id = o.user_id;
             
             let parm = {
              i:user.uniacid,
              id:id,
              ordertype:ordertype,
              user_id:user_id,
              bid:user.bid,
              token:user.token,
             }
             that.$fetch('app/index.php/?c=entry&a=wxapp&do=couinfo&m=mzhk_sun&calltest=?',parm)
             .then((res)=>{
              console.log('扫码核销的接口',res)
              if(res.code == 1){
               alert(res.msg)
              }else{
               if(ordertype == 10){
                that.bname = res.data.bname;
                that.couname = res.data.couname;
                that.limittime = res.data.limittime;
                that.type = 1;
                that.uid = res.data.uid
                if(res.data.isused == "0"){
                 that.isused = "未使用";
                }else if(res.data.isused == "1"){
                 that.isused = "已使用";
                }
               }else if(ordertype == 11){
                that.bname = res.data.bname;
                that.couname = res.data.fname;
                that.limittime = res.data.wtime;
                that.uid = res.data.openid;
                that.type = 1;
                if(res.data.isused == "0"){
                 that.isused = "未核销";
                }else if(res.data.isused == "1"){
                 that.isused = "已核销";
                }

               }
              }

             })
           })
         })
       })
     })
    

     }, 300);
     
     
     
    }

所以用了这个,用了这个的话,在安卓端和ios端都可以掉的起来。

以上就是vue调用微信jsdk 扫一扫,相册等需要注意的事项的详细内容,更多关于vue 调用微信扫一扫和相册的资料请关注其它相关文章!

《vue调用微信JSDK 扫一扫,相册等需要注意的事项.doc》

下载本文的Word格式文档,以方便收藏与打印。