一、配置了完整的config后为什么还是显示the permission value is offline verifying呢,安卓没问题而iphone手机会出现问题?
iphone手机获取路径是你
进入该网站第一个页面开始算(包括刷新页面)
所以,我们需要对url进行缓存处理,而安卓不用
二、处理问题(Vue)
①准备
/* utils/index.js */
// 判断ios
export function isIOS() {return navigator.userAgent.indexOf('iPhone') > -1
}
// 获取缓存的url
export function getIOSFirstUrl() {return store.getters.iOSFirstUrl
}
// 设置缓存的url
export function setIOSFirstUrl(url) {store.dispatch('setIOSFirstUrl', url)
}
/* store/modules/app.js */
// 在store做缓存
const state = {iOSFirstUrl: null,
}
const mutations = {SET_IOS_FIRST_URL(state, url) {state.iOSFirstUrl = url}
}
const actions = {setIOSFirstUrl({ commit }, url) {commit('SET_IOS_FIRST_URL', url)}
}
export default {state,mutations,actions
}
②实际使用
/* src\router\index.js */
// ...router自带的东西
const { wx } = window
router.afterEach(async (to, from) => {console.log('router afterEach', { from, to })const url = isIOS() ? getIOSFirstUrl() : window.location.href// 调用API获取的configgetJssdkConfig({url}).then(wxConfig => {wx.config(wxConfig)wx.ready(() => {wx.updateTimelineShareData(/*对应配置*/)wx.updateTimelineShareData(/*对应配置*/)})})
})
router.beforeEach(async (to, from, next) => {// ... 业务逻辑// 没有就设置到缓存if (!getIOSFirstUrl()) {setIOSFirstUrl(window.location.href.split('#')[0])}// ... 业务逻辑
})
// ...router自带的东西