周凯,个人博客

  • 前端
  • 嵌入式
  • 工具
  • 后端
  • 随笔
个人记录
  1. 首页
  2. 前端
  3. vue2
  4. 正文

uni-app制作h5加载weixin js-sdk wx.miniProgram undefined

2023年 9月 20日 858点热度 0人点赞 0条评论

问题

  • 使用uni-app制作h5,在h5中加载了微信的js-sdk,发现调用wx.miniProgram.navigateTo 方法显示undefined

解决

  • 在项目的App.vue中动态加载js

  • 代码如下

    onLaunch() {
      this.getLoadJs();
    }, 
    methods: {
      getLoadJs() {
        if (
          Utils.determineTheEnvironment() ===
          Constant.miniProgramEnvironment.alipay
        ) {
          Logs.info("支付宝js-sdk加载============");
          const script = document.createElement("script");
          script.src = "https://appx/web-view.min.js";
          document.body.appendChild(script);
        } else if (
          Utils.determineTheEnvironment() ===
          Constant.miniProgramEnvironment.weixin
        ) {
          Logs.info("微信js-sdk加载============");
          const script = document.createElement("script");
          script.src = "static/js/weixin-1.3.2.js";
          document.body.appendChild(script);
        }
      },
    }
  • 工具类在 小程序环境判断 - 周凯,个人博客 (start6.cn)

  • 微信js-sdk相关文档:开放能力 / web-view (qq.com)

    • js-sdk:weixin-1.3.2

🎯 拓展阅读提示

本文涉及的内容已同步至公众号后台,我会在那里分享更多深度内容和实用技巧

→ 点击关注:一行梦境

公众号二维码
本作品采用 知识共享署名 4.0 国际许可协议 进行许可
标签: 暂无
最后更新:2023年 9月 20日

周凯

这个人很懒,什么都没留下

打赏 点赞
< 上一篇
下一篇 >

文章评论

razz evil exclaim smile redface biggrin eek confused idea lol mad twisted rolleyes wink cool arrow neutral cry mrgreen drooling persevering
取消回复

COPYRIGHT © 2022-现在 周凯,个人博客. ALL RIGHTS RESERVED.

Theme Kratos Made By Seaton Jiang

蒙ICP备18004897号