国产成人精品久久免费动漫-国产成人精品天堂-国产成人精品区在线观看-国产成人精品日本-a级毛片无码免费真人-a级毛片毛片免费观看久潮喷

您的位置:首頁技術文章
文章詳情頁

基于vue hash模式微信分享#號的解決

瀏覽:134日期:2022-06-11 16:35:23

看代碼吧~

// 問題描述在微信中分享到朋友圈或好友時,分享出去的路由被破壞,打開分享的鏈接,路由中的“#”會被去掉并追加?fromTimeline之類的后綴參數,這就造成了分享出去的鏈接只能進入首頁,無法正常跳轉到其他路由。 // 獲取簽名 this.$ajax.post(this.apiUrl+'/api/wxShare/getWxConfig', this.$qs.stringify({'url':window.location.href.split(’#’)[0]})).then((res) => {//有人說要加轉譯encodeURIComponent本人沒加具體跟你們的后臺協商 if (res.data.status.code === ’0000’) { wx.config({ debug: false, appId: res.data.data.appid, timestamp: res.data.data.timestamp, nonceStr: res.data.data.nonceStr, signature: res.data.data.signature, jsApiList: [’onMenuShareTimeline’,’onMenuShareAppMessage’ ] }); } }) //處理驗證失敗的信息 wx.error(function (res) { alert(’驗證失敗返回的信息:’,res); }); console.log(window.location.href.split(’#’)[0]) wx.ready(function () { // 分享給朋友 wx.onMenuShareAppMessage({ title: ’這是標題’, // 分享標題 desc: '這是測試的數據', // 分享描述 link: window.location.href.split(’#’)[0]+’#’+window.location.href.split(’#’)[1], // 分享鏈接!這里是關鍵 因為微信會把我們分享的鏈接截取掉 我在這里手動拼接上 imgUrl: ’’, // 分享圖標 type: ’’, // 分享類型,music、video或link,不填默認為link dataUrl: ’’, // 如果type是music或video,則要提供數據鏈接,默認為空 success: function () { window.alert(’已分享給好友’); }, cancel: function () { // 用戶取消分享后執行的回調函數 }, fail: function (res) { window.alert(JSON.stringify(res)); } }); // 分享到朋友圈 wx.onMenuShareTimeline({ title: ’這是標題’, // 分享標題 desc: '這是測試的數據', // 分享描述 link: window.location.href.split(’#’)[0]+’#’+window.location.href.split(’#’)[1], // 分享鏈接 success: function () { window.alert(’已分享到朋友圈’); }, cancel: function () { }, fail: function (res) { window.alert(JSON.stringify(res)); } });

補充知識:解決video標簽播放在微信瀏覽器中自動全屏的坑(vue-video-player使用后續)

屬性熟悉

下面是微信video中幾個Attribute的作用

poster=“loadbg.jpg” : 視頻封面

x-webkit-airplay=“allow” : 允許iOS的airplay

x5-video-player-type=“h5” : 啟用x5內核的播放器,是微信安卓版特性,另外在X5內核里,video是單獨的一個view,會覆蓋在任何元素之上,據說是為了統一用戶體驗,加上這個屬性之后,也可以讓其他元素浮在video上面了

x5-playsinline=“true”: 在x5內核的播放器中小屏播放

x5-video-player-fullscreen=“true”: 全屏設置,設置為 true 是防止橫屏

x5-video-orientation=“portraint”: 播放方向,landscape橫屏,portraint豎屏,默認值為豎屏

webkit-playsinline=“true”: 這個屬性是iOS中設置可以讓視頻在小窗內播放,也就是不是全屏播放

playsinline=“true”: IOS微信瀏覽器支持小窗內播放

思路與初嘗試

上面屬性熟悉后,有了些思路, 不就是把上面要的屬性都寫一遍嗎,這樣iOS端和android端微信都能起作用, 然鵝, 實際情況并非如此。 經過我無數次嘗試, 總結出就是得分開寫!!

代碼修改

之前:playsinline='playsinline'這里是true寫死的,現在改為計算屬性playsinline(),代碼如下

<video-player ref='videoPlayer' :options='playerOptions' :playsinline='playsinline' customEventName='customstatechangedeventname' @play='onPlayerPlay($event)' @pause='onPlayerPause($event)' @ended='onPlayerEnded($event)' @waiting='onPlayerWaiting($event)' @playing='onPlayerPlaying($event)' @loadeddata='onPlayerLoadeddata($event)' @timeupdate='onPlayerTimeupdate($event)' @canplay='onPlayerCanplay($event)' @canplaythrough='onPlayerCanplaythrough($event)' @statechanged='playerStateChanged($event)' @ready='playerReadied'> </video-player>

添加playsinline()這個計算屬性,原因是在安卓和iOS端微信使用的內核不同,所需要的attribute也不同,嘗試后,采用x5內核返回false,反之為true

computed: { playsinline(){ var ua = navigator.userAgent.toLocaleLowerCase(); //x5內核 if (ua.match(/tencenttraveler/) != null || ua.match(/qqbrowse/) != null) { return false }else{ //ios端 return true } } },

配合jq工具,繼續添加兩個端所需的屬性

//在vue-video-player的onPlayerCanplay(視頻可播放)這個方法中添加回調onPlayerCanplay(player) { // console.log(’player Canplay!’, player) //解決自動全屏 var ua = navigator.userAgent.toLocaleLowerCase(); //x5內核 if (ua.match(/tencenttraveler/) != null || ua.match(/qqbrowse/) != null) {$(’body’).find(’video’).attr(’x-webkit-airplay’,true).attr(’x5-playsinline’,true).attr(’webkit-playsinline’,true).attr(’playsinline’,true) }else{ //ios端 $(’body’).find(’video’).attr(’webkit-playsinline’,'true').attr(’playsinline’,'true') } }

總結

以區分兩個端內核的不同,按需添加所需的Attribute

':playsinline'組件中自定義屬性按內核不同按需傳值, x5內核為false,反之為true然后來渲染組件(具體原理有待挖掘)

以上這篇基于vue hash模式微信分享#號的解決就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持好吧啦網。

標簽: 微信
相關文章:
主站蜘蛛池模板: 日韩精品一区二区三区高清 | 欧美一区二区在线观看视频 | 99久久亚洲综合精品网站 | 日本欧美一区二区三区高清 | 欧美一区二区三区不卡 | 日韩精品欧美激情国产一区 | 国产精品推荐 | 91刘亦菲精品福利在线 | 女人张开腿让男人桶视频 | 草草影院ccyycom浮力影院 | 手机看片福利永久 | 欧美野外性xxxxfeexxxxx | 欧美黄成人免费网站大全 | 男操女免费视频 | 国产一级做a爰片在线看 | 亚洲精品推荐 | 精品一区二区三区免费毛片爱 | 日本一级特黄特色大片免费视频 | 国产99久久久久久免费看 | 久色精品 | 欧美最爽乱淫视频播放黑人 | 精品国产一区二区三区成人 | 性刺激欧美三级在线现看中文 | 国产成人小视频 | 黄色网址网站 | 日本一级大毛片a一 | 国产麻豆一级在线观看 | 国产天堂 | 亚洲精品一区二区三区网址 | 国产精品怡红院在线观看 | 高清国产美女一级毛片 | 国产成人福利美女观看视频 | 91精品视频免费 | 中文字幕亚洲另类天堂 | 日韩在线视频观看 | 国产成人aa在线视频 | 免费看欧美一级特黄a毛片 免费看片aⅴ免费大片 | 成人三级精品视频在线观看 | 欧美性巨大欧美 | 宅女福利视频在线看免费网站 | 日本卡一卡2卡3卡4精品卡无人区 |