微信小程序扫普通链接二维码打开小程序

  • 微信后台 - 管理 -开发管理 -扫普通链接二维码打开小程序

  • 代码实现

        /**
        * 生命周期函数--监听页面加载
        */
        onLoad: function (option: any) {
          if (option.hasOwnProperty('q') && option.q) {
            // 通过下面这步解码,可以拿到url的值
            const url = decodeURIComponent(option.q) // 对url中携带的参数提取处理
            let jsonUrl = this.GetwxUrlParam(url);
            this.setData({
              'id': jsonUrl.id, // 微信后台里配置的id
            })
    
          }
        },
    
        GetwxUrlParam(url: any) {
          let theRequest: any = {};
          if (url.indexOf("#") != -1) {
            const str = url.split("#")[1];
            const strs = str.split("&");
            for (let i = 0; i < strs.length; i++) {
              theRequest[strs[i].split("=")[0]] = decodeURI(strs[i].split("=")[1]);
            }
          } else if (url.indexOf("?") != -1) {
            const str = url.split("?")[1];
            const strs = str.split("&");
            for (let i = 0; i < strs.length; i++) {
              theRequest[strs[i].split("=")[0]] = decodeURI(strs[i].split("=")[1]);
            }
          }
          return theRequest;
        },
    
posted @   不完美的完美  阅读(67)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· AI技术革命,工作效率10个最佳AI工具
历史上的今天:
2022-11-22 学习vue3.0
2022-11-22 学习react
2022-11-22 react基础+pc项目
2017-11-22 HTML5API(5)
点击右上角即可分享
微信分享提示