美文网首页
关于h5跳转小程序一些分享vue

关于h5跳转小程序一些分享vue

作者: 北上广_d8bd | 来源:发表于2021-05-27 09:27 被阅读0次

引入sdk

第一种: npm install weixin-js-sdk -D   import wx from 'weixin-js-sdk';
第二种: <script src="https://res.wx.qq.com/open/js/jweixin-1.6.0.js"></script>
切记:同时引入的话,第二种层级高;

页面 跳转地址记得加.html

<template>
  <div>
    <wx-open-launch-weapp id="launch-btn" username="小程序原始id" path="/pages/index/index.html">
      <script type="text/wxtag-template">
        <button class="btn" style="display:block;width:200px;height:100px;background-color:red;">打开小程序</button>
      </script>
    </wx-open-launch-weapp>
  </div>
</template>

定义config:

 data () {
    return {
      vxConfig: {
        debug: true,
        appId: '',
        timestamp: '',
        nonceStr: '',
        signature: '',
        jsApiList: ["checkJsApi", 'openLocation'], // 随便写一个就好
        openTagList: ["wx-open-launch-weapp"] // 跳转小程序时必填
      },
    }
  },

调用后台设置config

 wxconfig () {
      let signLink = /(Android)/i.test(navigator.userAgent) ? location.href.split('#')[0] : window.entryUrl; // 兼容hash、history模式
      if (wx == null) {
        return;
      }
      $.ajax({
        type: 'POST',
        url: location.protocol + '//' + location.host + 'xxxxxxxxxx', // 请求自己后台地址
        dataType: 'json',
        timeout: 6e3,
        data: {
          'url': signLink,
        },
        success: (rData) => {
          if (rData) {
            this.vxConfig.appId = rData.appId;
            this.vxConfig.timestamp = rData.timestamp;
            this.vxConfig.nonceStr = rData.nonceStr;
            this.vxConfig.signature = rData.signature;
            wx.config(this.vxConfig);
            wx.ready(function () {
              console.log('ready')
            });
          }
        }, error: (err) => {
          console.log(err)
        },
      })
    },

调用方法

 // 目前不加定时按钮不显示 所以加了定时  有解决的小伙伴希望分享一下此解决办法
 setTimeout(() => {
      this.wxconfig();
    }, 1000);

关于样式 目前只支持px 有好的方法可以分享 本人自身项目用的rem

相关文章

  • 关于h5跳转小程序一些分享vue

    引入sdk 页面 跳转地址记得加.html 定义config: 调用后台设置config 调用方法 关于样式 目...

  • 小程序和h5跳转

    公司要做h5跳转小程序,就试着调试了一下。目前只支持小程序内嵌H5,并且只有内嵌的H5才能跳回小程序 小程序跳H5...

  • H5跳小程序

    H5跳转小程序分两种情况,一种是小程序内部打开的H5跳转小程序,一种是在外部的H5跳转到小程序 小程序内部打开的H...

  • uni-app vant/weapp Cannot read p

    因为之前的h5项目是vue+vant ,现在需要转小程序,于是选择了uni-app+ vant/weapp,但随之...

  • h5跳转小程序之静态网页

    首先h5跳转小程序的方式有很多,这里说得不是小程序中嵌套h5页面,而是单纯的一个(外部的)h5页面跳转小程序,我的...

  • 小程序和H5页面互相跳转的实现

    需求体现: 在小程序里面,实现小程序和H5页面互相跳转。 1. 实现H5页面跳转小程序 小程序里面加载H5页面,需...

  • vue项目-h5跳转小程序

    根据微信的开放标签wx-open-launch-weapp可以实现从h5页面跳转小程序的需求微信文档地址:http...

  • React开发-公众号H5跳转小程序

    正需要H5跳转小程序的时候 前几天还在发愁怎么改产品, 这几天这个能力就来了, 因为很多人写的是Vue或者js中使...

  • 使用uniapp开发小程序rich-text组件生成图片过宽怎么

    1、在App.vue组件中(h5),直接在App.vue修改即可: 2、2、关于小程序里面图片溢出问题,这里借鉴一...

  • h5跳转微信小程序

    微信小程序web-view中内嵌的h5页面,跳转小程序 微信小程序文档:https://developers.we...

网友评论

      本文标题:关于h5跳转小程序一些分享vue

      本文链接:https://www.haomeiwen.com/subject/yjjrsltx.html