解决iOS跳转页面被浏览器缓存不会自动刷新页面问题
微信服务号开发时今日支付页面支付时iOS会出现当前链接还是上一个页面的链接导致微信支付失败,提示当前页面的url未注册,解决方案是判断如果是iOS的话进入该页面就自动刷新一遍。
路由文件index.js里:
router.beforeEach((to, from, next) => { // ... if (from.name != null || to.name != "toPay"){ let u = navigator.userAgent; let isAndroid = u.indexOf('Android') > -1 || u.indexOf('Adr') > -1; //android终端 let isiOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios终端 localStorage.setItem("isiOS", true) } if (to.query.ticket){ api.userIsLogin().then(res => { localStorage.setItem("userIsLogin", res) if (res == false) { api.getUsername(to.query.ticket).then(res => { console.log('getUsername', res) api.getMyInfo().then(res => { // alert("获取我的信息"+JSON.stringify(res)) console.log("获取我的信息", res) next() }) }) } else { next() } }) }else{ console.log(to, from, location.href, querystring.parse()) next() } })
支付页里:
mounted () { if(location.search){ location.href = location.href.replace(location.search,"") }else{ if(localStorage.getItem("isiOS") == "true"){ localStorage.removeItem("isiOS") window.location.reload(); } } },