收藏
回答

wx-open-launch-app启动不了没在后台运行的app?

代码:

          
            打开APP查看
           
 
export default {
  data() {
    return {
      isWeiXin:true,
    };
  },
  mounted() {
      // 检查微信 SDK 是否加载
      console.log('检查微信 SDK 是否加载',window.wx);
      // 检查按钮 DOM 是否存在
      console.log('检查按钮 DOM ',document.getElementById('launch-btn'));
      // 检查微信 SDK 配置
      console.log('当前URL:', window.location.href.split('#')[0]);
    if(this.isWeiXin){
      const btn = document.getElementById('launch-btn');
      this.handleSdk()
   }
  },
  methods: {
    handleSdk(){
      var urls = window.location.href.split('#')[0];
        this.$axios.post('/oss/wechatAuth/h5JumpMini', {
          url: urls
        }).then((res) => {
          console.log(res)
         if (res.data.rel) {
          wx.config({
            debug: true, // 开启调试模式,调用的所有 api 的返回值会在客户端 alert 出来,若要查看传入的参数,可以在 pc 端打开,参数信息会通过 log 打出,仅在 pc 端时才会打印
            appId: res.data.data.appId, // 必填,公众号的唯一标识
            timestamp: res.data.data.timestamp, // 必填,生成签名的时间戳
            nonceStr: res.data.data.nonceStr,// 必填,生成签名的随机串
            signature: res.data.data.signature,// 必填,签名
            jsApiList: ["wx-open-launch-app","onMenuShareAppMessage", "onMenuShareTimeline"], // 必填,随意一个接口即可 , // 必填,需要使用的 JS 接口列表
            openTagList: ["wx-open-launch-app"], // 关键!必须声明开放标签
          })
          wx.checkJsApi({
            jsApiList:  ['wx-open-launch-app'], // 校验跳转APP的标签是否可用
            success: function (res) {
                console.log('可用')
            },
            fail: (err) => {
                console.log(err, '不可用')
            }             
          })
              wx.error(function (res) {
            console.log(res, 'error');
            // config信息验证失败会执行error函数,如签名过期导致验证失败,具体错误信息可以打开config的debug模式查看,也可以在返回的res参数中查看,对于SPA可以在这里更新签名
          });
        }
         
        }
      })
    },
   onListenLaunchError(e) {
        // window.location.replace('应用商店地址');
      },
      handlelaunch(){
        console.log('链接跳转');
      },
  
   },
};


最后一次编辑于  04-18
回答关注问题邀请回答
收藏

1 个回答

登录 后发表内容