javascript - 關(guān)于使用axios和vue開(kāi)發(fā) 手機(jī)端瀏覽器返回的時(shí)候讀取緩存無(wú)法執(zhí)行js和vue組件
問(wèn)題描述
一個(gè)手機(jī)端的網(wǎng)站 在一個(gè)頁(yè)面進(jìn)行了檢測(cè)登錄限制 如果沒(méi)登錄就到登錄頁(yè) 但是到了登錄頁(yè)按返回鍵還是能回到第一個(gè)頁(yè) 并且不讀取任何數(shù)據(jù)和圖片 求問(wèn)怎么才能讓他后退的時(shí)候是刷新網(wǎng)頁(yè)而不是讀取緩存的網(wǎng)站
問(wèn)題解答
回答1:window.location.replace()參數(shù)寫(xiě)你要跳轉(zhuǎn)的路由地址(本頁(yè)面不會(huì)產(chǎn)生緩存,瀏覽器不會(huì)有后退選項(xiàng),如果需要產(chǎn)生后退選項(xiàng)把“replace”換成assign);
回答2:如果你的項(xiàng)目中有用到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...
如果沒(méi)有用到vue-router 可以把登錄判斷放到 beforeCreate 中做檢測(cè)
相關(guān)文章:
1. [python2]local variable referenced before assignment問(wèn)題2. 求救一下,用新版的phpstudy,數(shù)據(jù)庫(kù)過(guò)段時(shí)間會(huì)消失是什么情況?3. mysql - 如何在有自增id的情況下,讓其他某些字段能不重復(fù)插入4. python小白,關(guān)于函數(shù)問(wèn)題5. django - Python error: [Errno 99] Cannot assign requested address6. Python2中code.co_kwonlyargcount的等效寫(xiě)法7. java - 線(xiàn)上應(yīng)用,如果數(shù)據(jù)庫(kù)操作失敗的話(huà)應(yīng)該如何處理?8. node.js - win 下 npm install 遇到了如下錯(cuò)誤 會(huì)導(dǎo)致 無(wú)法 run dev么?9. python小白 關(guān)于類(lèi)里面的方法獲取變量失敗的問(wèn)題10. angular.js - 百度支持_escaped_fragment_嗎?
