html5跳轉(zhuǎn)小程序wx-open-launch-weapp踩坑

因為IOS最新版微信取消了浮窗功能,小程序后臺狠毒用戶反饋進入不方便了,目前公眾號還支持浮窗,于是需求出來了,浮窗一個H5,在H5中一鍵打開小程序,閱讀文檔得知,微信對公眾號網(wǎng)頁開發(fā)有開放標簽,可以打開App或小程序,但是過程中遇到不少坑以下為記錄爬坑。
1.正常操作,公眾號后臺綁定域名
2.引入weixin.js 目前是1.6.0版本
3.調(diào)用wx.config 在openTagList中加入要使用的開放標簽
接下來坑來了,文檔上使用示例如下
<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中 無法使用,排查發(fā)現(xiàn)是template標簽的問題
<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>
這樣基本功能就實現(xiàn)了,但是樣式?jīng)]法居中,在里面寫的style很多不生效,最后解決方案是: 給開放標簽外部套一個div 給div寫樣式,開放標簽本身也可以通過ID選擇器直接寫樣式, 至此開發(fā)完成,后續(xù)老板想在created中直接模擬點擊按鈕喚起小程序,試了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踩坑 的文章就介紹到這了,更多相關(guān)html5跳轉(zhuǎn)小程序內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持腳本之家!
相關(guān)文章
HTML5跳轉(zhuǎn)小程序wx-open-launch-weapp的示例代碼
這篇文章主要介紹了HTML5跳轉(zhuǎn)小程序wx-open-launch-weapp的相關(guān)知識,本文給大家介紹的非常詳細,對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2020-07-16