微信內部瀏覽器跳轉微信小程序(h5跳轉微信小程序)


<template>
//position: fixed不加這個自己的樣式可能出不來
  <div class="wxs" style="position: fixed">
    <wx-open-launch-weapp
      username="gh_"
      path="/pages/home/index.html"
    >
      <script type="text/wxtag-template">
        <style>.btn { width: 100%;height: 100%;}</style>
        <style>.img1{ width: 100%;height: 100%;object-fit: contain;}</style>
        <div class="btn" >
           <img class="img1" src="" alt="">
        </div>
      </script>
    </wx-open-launch-weapp>
  </div>
</template>
<script>
export default {
  data() {
    return {
      username: "",
    };
  },
  methods: {
    wxmini() {
      // 獲取密鑰
      this.$api.publicapi.getWxinfo().then((res) => {
        wx.config({
          // eslint-disable-line
          debug: false, // 開啟調試模式,調用的所有api的返回值會在客戶端alert出來,若要查看傳入的參數,可以在pc端打開,參數信息會通過log打出,僅在pc端時才會打印
          appId: res.data.appid, // 必填,公眾號的唯一標識
          timestamp: res.data.timestamp, // 必填,生成簽名的時間戳
          nonceStr: res.data.nonceStr, // 必填,生成簽名的隨機串
          signature: res.data.signature, // 必填,簽名
          jsApiList: ["onMenuShareTimeline", "chooseImage", "previewImage"], // 必填,需要使用的JS接口列表
          openTagList: ["wx-open-launch-weapp"], // 可選,需要使用的開放標簽列表,例如['wx-open-launch-app']
        });
        /* eslint-disable */
        wx.ready(function () {});
        wx.error(function () {
          alert("您的版本號不支持跳轉微信小程序");
        });
      });
    },
  },
  created() {
    const oScript = document.createElement("script");
    oScript.type = "text/javascript";
    oScript.src = "https://res2.wx.qq.com/open/js/jweixin-1.6.0.js";
    oScript.onload = this.wxmini();
    document.body.appendChild(oScript);
  },
};
</script>


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM