vue中,一個(gè)列表頁(yè)從列表詳情頁(yè)返回需要被緩存,從其他頁(yè)面進(jìn)入列表不需要緩存,我在main.js中設(shè)置router.beforeEach((to,from,next)=>{Vue.prototype.fromurl=from.path;Vue.prototype.tourl=to.meta;if(from.path.substr(3,4)=='shop'){varbostonetop=$(window).scrollTop();localStorage.setItem("bostonetop",bostonetop)}elseif(from.path.substr(3,13)=='special_field'){varbostonetop=$(window).scrollTop();localStorage.setItem("bostonetop",bostonetop)}if(to.path.substr(3,4)=='shop'){if(from.path.substr(3,14)=='product_detail'){//思路是進(jìn)入列表頁(yè)并從詳情頁(yè)返回加載緩存,其他不加載緩存to.meta.keepAlive=true;varbostonetop=localStorage.getItem("bostonetop")$('html,body').animate({scrollTop:bostonetop},10);}}elseif(to.path.substr(3,13)=='special_field'){if(from.path.substr(3,14)=='product_detail'){to.meta.keepAlive=true;varbostonetop=localStorage.getItem("bostonetop")$('html,body').animate({scrollTop:bostonetop},10);}}else{to.meta.keepAlive=false}next()})App.vuerouter.js{path:'/t/shop',name:'shop',component:shop,meta:{keepAlive:true}},RT,思路是進(jìn)入該列表頁(yè)并從詳情頁(yè)返回加載緩存,其他不加載緩存。但是實(shí)際中所有頁(yè)面進(jìn)入該頁(yè)面中都產(chǎn)生了緩存;這不是我想要的,請(qǐng)問上述問題應(yīng)該如何解決?如何從其他頁(yè)面進(jìn)入該頁(yè)面不加載緩存并從詳情返回加載緩存?
vue使用緩存產(chǎn)生的問題如何解決?
BIG陽
2019-05-08 16:50:11