因?yàn)镮OS最新版微信取消了浮窗功能,小程序后臺(tái)狠毒用戶反饋進(jìn)入不方便了,目前公眾號(hào)還支持浮窗,于是需求出來(lái)了,浮窗一個(gè)H5,在H5中一鍵打開小程序,閱讀文檔得知,微信對(duì)公眾號(hào)網(wǎng)頁(yè)開發(fā)有開放標(biāo)簽,可以打開App或小程序,但是過(guò)程中遇到不少坑以下為記錄爬坑。
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)簽的問(wèn)題
<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)簽本身也可以通過(guò)ID選擇器直接寫樣式, 至此開發(fā)完成,后續(xù)老板想在created中直接模擬點(diǎn)擊按鈕喚起小程序,試了ref獲取dom后調(diào)用click方法可是不生效,發(fā)現(xiàn)論壇上也沒有相關(guān)解決方案,微信開放社區(qū)中也有相關(guān)問(wèn)題掛起并未解決,大家要是有什么好的方法可以下面討論下一起解決下
另附微信開放社區(qū)問(wèn)題掛起的地址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)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持腳本之家!
標(biāo)簽:池州 棗莊 西藏 遼源 漯河 新疆 永州 青島
巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《html5跳轉(zhuǎn)小程序wx-open-launch-weapp踩坑》,本文關(guān)鍵詞 html5,跳轉(zhuǎn),小,程序,wx-open-launch-weapp,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問(wèn)題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無(wú)關(guān)。