1:keep-alive生效的前提挽铁,組件都要聲明一個(gè)name屬性,并確保唯一性
2:A/C跳轉(zhuǎn)B頁(yè)面敞掘,返回A/C,緩存C二級(jí)路由叽掘,則需要同時(shí)緩存一級(jí)路由A,否則緩存不生效,設(shè)置緩存需要寫(xiě)在beforeRouteEnter里面
beforeRouteEnter(to, from, next) {
next(vm => {
//詳情->私募待辦(銷(xiāo)毀)->我的理財(cái)之后玖雁,再走我的理財(cái)->私募待辦(緩存)->詳情的時(shí)候更扁,寫(xiě)在routeLeave的時(shí)候緩存失效
vm.$store.commit('setInclude', ['user', 'privateContractPending'])
})
},
beforeRouteLeave(to, from, next) {
if (to.name !== 'detail') {
this.$store.commit('setInclude', [])
this.$destroy()
}
next()
},
寫(xiě)在routeLeave中出現(xiàn)的問(wèn)題:
A/B->A/C->D,然后D->A/C緩存這時(shí)是生效的赫冬,但是再接著繼續(xù)返回到A/B,再走A/C->D,再走D->A/C發(fā)現(xiàn)沒(méi)有緩存
beforeRouteLeave(to, from, next) {
if(to.name === 'detail'){
this.$store.commit('setInclude', ['user', 'privateContractPending'])
}else{
this.$store.commit('setInclude', [])
this.$destroy()
}
}