记一次vue静态页面跳转微信小程序

功能

1.普通图片点击跳转小程序

2.轮播图跳转小程序

实现

1.普通图片跳转微信小程序十分简单,官网有教程,在这里展示一下我的代码

//标签代码          
  <wx-open-launch-weapp
              id="launch-btn"
              username="小程序原始idf"
              :path="目标小程序页面地址"
            >
               <script type="text/wxtag-template">
                <style>.btn {width: 414px; height: 200px;opacity:0;}</style>
                <img :src="item.ad_image" class="btn"/>//这一段根据自己的需求随便写,但是必须要有内容必须有大小。
              </script>
            </wx-open-launch-weapp> 

//JS代码
axios({
      method: "POST",
      url: 接口地址,
      data: { url: href },
    }).then(function (res) {
      console.log(res);
      if (res.status == 200) {
        console.log(res.data.sign);
        wx.config({
          debug: false,
          appId: res.data.appid,
          timestamp: res.data.timestamp,
          nonceStr: res.data.nonce_str,
          signature: res.data.sign,
          jsApiList: ["scanQRCode"],
          openTagList: ["wx-open-launch-weapp"], // 可选,需要使用的开放标签列表,例如[‘wx-open-launch-weapp’]
        });
        wx.error(function (res) {
          console.log(res);
          // config信息验证失败会执行error函数,如签名过期导致验证失败,具体错误信息可以打开config的debug模式查看,也可以在返回的res参数中查看,对于SPA可以在这里更新签名。
        });
      }
    });

这个接口是专门用来获取wx.config中参数的,我之前脑子一抽自己就写了,后边还得改回来。

wx.config中的代码是用来向wx官网获取微信开放标签的使用权限,注意!!!!必须是将项目部署到服务器上,把这个域名交给后台,让他把你的域名添加到小程序安全域名里边。

2.轮播图跳转小程序   我轮播图用的element ui

<el-carousel :interval="5000" arrow="always" >
    <el-carousel-item v-for="(item,index) in mainImg" :key="index" >

      <!-- <div style="height:200px" v-for="(item1,index) in canshu" :key="index"> -->
        <div>
          <div
            style="
              width: 414px;
              height: 200px;
              opacity: 0;
              position: absolute;
              z-index: 7777;
             
            "
          >
            <wx-open-launch-weapp
              id="launch-btn"
              username="原始id"
              :path="地址"
            >
               <script type="text/wxtag-template">
                <style>.btn {width: 414px; height: 200px;opacity:0;}</style>
                <img :src="item.ad_image" class="btn"/>
              </script>
            </wx-open-launch-weapp> 
          </div>
          <img :src="item.ad_image" style="position: relative; z-index: 1;width: 414px;height:200px;" >
        </div>
    </el-carousel-item>
  </el-carousel>

另外,我在使用时,发现在手机上轮播图左右滑动与轮播图跳转小程序是不能一起实现的,在网上也没有找到解决办法,各位大佬如果有解决的思路还请在下方留言。

第一次写文章,有什么表述不清楚的,可以留言问我呦。

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值