在开发微信h5分享时出现了ios只会在初始化首页的时候进行初始化设置,后面相对个别页面进行特殊化配置的时候,比如跳转链接,图片的修改 在ios上无法生效,但在安卓上是有效的.
原因是:ios是只在进入链接的第一次进行获取
解决:
vue尽量使用hash模式.
1.分享的js中
newpath = window.entryUrl || newpath = window.location.href.split('#')[0]
export function wechatshare (
title,
desc,
shareimage,
shareurl,
path,
fxstr,
type,
issource,
isfirst,
iszy,
scontent
) {
let newpath = path
if (window.__wxjs_is_wkwebview === true) {
newpath = window.location.href.split('#')[0] || window.location.href
if (/(iPhone|iPad|iPod|iOS)/i.test(navigator.userAgent)) {
newpath = window.entryUrl
}
} else {
// newpath = window.location.href
newpath = window.location.href.split('#')[0]
}
getJsSign({
url: newpath
}).then()
}
2.wxapi.js中 调整newpath
// 获取微信配置
export function getConfig (path, type) {
let newpath = path
if (window.__wxjs_is_wkwebview === true) {
newpath = window.location.href.split('#')[0] || window.location.href
if (/(iPhone|iPad|iPod|iOS)/i.test(navigator.userAgent)) {
newpath = window.entryUrl
}
} else {
newpath = window.location.href
}
GetwxConfig({ url: newpath }).then()
}
3.router.js路由中
router.afterEach((to, from) => {
window.document.title = to.meta.title
? to.meta.title
: getStorage('sys_info', {}).appsysname
if (!window.entryUrl && /(iPhone|iPad|iPod|iOS)/i.test(navigator.userAgent)) {
var url = window.location.href.split('#')[0]
window.entryUrl = url // 将后面的参数去除
}
})