javascript - 關(guān)于使用axios和vue開發(fā) 手機端瀏覽器返回的時候讀取緩存無法執(zhí)行js和vue組件
問題描述
一個手機端的網(wǎng)站 在一個頁面進行了檢測登錄限制 如果沒登錄就到登錄頁 但是到了登錄頁按返回鍵還是能回到第一個頁 并且不讀取任何數(shù)據(jù)和圖片 求問怎么才能讓他后退的時候是刷新網(wǎng)頁而不是讀取緩存的網(wǎng)站
問題解答
回答1:window.location.replace()參數(shù)寫你要跳轉(zhuǎn)的路由地址(本頁面不會產(chǎn)生緩存,瀏覽器不會有后退選項,如果需要產(chǎn)生后退選項把“replace”換成assign);
回答2:如果你的項目中有用到vue-router 可以用router.beforeEach 參考下面代碼
router.beforeEach((to, from, next) => { store.commit(’SET_MODULE’, to.meta.module) if (to.matched.some(record => record.meta.requiresAuth === true)) { if (store.getters.token === ’’) { next({path: ’/sign’,query: {redirect: to.fullPath} }) } else { next() } } else if (to.matched.some(record => record.meta.requiresAuth === false)) { if (store.getters.token !== ’’) { next(to.query.redirect || ’/m’) } else { next() } } else { next() }})
https://github.com/ycloud/cno...
如果沒有用到vue-router 可以把登錄判斷放到 beforeCreate 中做檢測
相關(guān)文章:
