App下載

在html5跳轉(zhuǎn)小程序使用wx-open-launch-weapp使用方法總結(jié)!防踩坑!

發(fā)呆業(yè)務(wù)愛好者 2021-08-18 15:04:14 瀏覽數(shù) (7385)
反饋

我們對(duì)于小程序現(xiàn)在應(yīng)該大家有知道怎么使用了,那么我們今天就來(lái)講講有關(guān)于:“在html5跳轉(zhuǎn)小程序使用wx-open-launch-weapp使用方法總結(jié)!”這方面的相關(guān)內(nèi)容分享!

1.正常操作,公眾號(hào)后臺(tái)綁定域名
2.引入weixin.js 目前是1.6.0版本
3.調(diào)用wx.config 在openTagList中加入要使用的開放標(biāo)簽
接下來(lái)坑來(lái)了,文檔上使用示例如下

<wx-open-launch-weapp
  id="launch-btn"
  username="gh_xxxxxxxx"
  path="pages/home/index.html?user=123&action=abc"
>
  <template>
<style>.btn { padding: 12px }</style>
<button class="btn">打開小程序</button>
  </template>
</wx-open-launch-weapp>
<script> var btn = document.getElementById('launch-btn');
  btn.addEventListener('launch', function (e) {
console.log('success');
  });
  btn.addEventListener('error', function (e) {
console.log('fail', e.detail);
  }); </script> 

貼在vue中 無(wú)法使用,排查發(fā)現(xiàn)是template標(biāo)簽的問題:

<div class="center" style="width: 100%" ref="launchBtnHome">
      <wx-open-launch-weapp id="launch-btn" username="gh_xxxxxxxx" path="pages/index/index/index" ref="launchBtn">
        <script type="text/wxtag-template">
          <style>
            .jump-btn {
              height: 44px;
              line-height: 44px;
              border: none;
              font-size: 16px;
              color: #ffffff;
              background-color: #f94048;
              text-align: center;
            }
          </style>
          <div class="jump-btn">打開小程序</div>
        </script>
      </wx-open-launch-weapp>
    </div>

這樣基本功能就實(shí)現(xiàn)了,但是樣式?jīng)]法居中,在里面寫的style很多不生效,最后解決方案是: 給開放標(biāo)簽外部套一個(gè)div 給div寫樣式,開放標(biāo)簽本身也可以通過ID選擇器直接寫樣式, 至此開發(fā)完成,后續(xù)老板想在created中直接模擬點(diǎn)擊按鈕喚起小程序,試了ref獲取dom后調(diào)用click方法可是不生效,發(fā)現(xiàn)論壇上也沒有相關(guān)解決方案,微信開放社區(qū)中也有相關(guān)問題掛起并未解決,大家要是有什么好的方法可以下面討論下一起解決下

另附微信開放社區(qū)問題掛起的地址https://developers.weixin.qq.com/community/develop/doc/0004604a1d8df03099ba91c965b400

那么以上就是有關(guān)于:“在html5跳轉(zhuǎn)小程序使用wx-open-launch-weapp使用方法總結(jié)!”這方面的全部?jī)?nèi)容了,希望小編的分享對(duì)大家有所幫助!更多有關(guān)于html5這方面的相關(guān)內(nèi)容我們都可以在W3Cschool進(jìn)行學(xué)習(xí)和了解!


0 人點(diǎn)贊