vue框架做的項目有一個問題,就是ios端圖片無法長按轉(zhuǎn)發(fā)裆蒸,這其實是微信內(nèi)部機制的問題熔萧。那我們怎么來處理呢?
辦法還是有的光戈,在路由進入當(dāng)前頁面前beforeRouteEnter處理一下哪痰。具體代碼。把他的url的內(nèi)容換掉久妆。
beforeRouteEnter(to, from, next) {
// 修復(fù)iOS版微信h5 History兼容性問題
? ? if (isIOS() && to.path !== location.pathname) {
location.assign(to.fullPath); // 此處不可使用location.replace
? ? }else {
next();
? ? }
},
這個isIos方法是這樣實現(xiàn)的晌杰。判斷是否ios手機.這樣就可以啦嘻嘻。
/**
* 查看手機是不是ios
* */
export function isIOS() {
var isIphone = navigator.userAgent.includes('iPhone');
? ? var isIpad = navigator.userAgent.includes('iPad');
? ? return isIphone || isIpad;
}