1:keep-alive生效的前提,組件都要聲明一個name屬性,并確保唯一性
2:A/C跳轉(zhuǎn)B頁面,返回A/C,緩存C二級路由,則需要同時緩存一級路由A,否則緩存不生效,設(shè)置緩存需要寫在beforeRouteEnter里面
beforeRouteEnter(to, from, next) {
next(vm => {
//詳情->私募待辦(銷毀)->我的理財之后,再走我的理財->私募待辦(緩存)->詳情的時候,寫在routeLeave的時候緩存失效
vm.$store.commit('setInclude', ['user', 'privateContractPending'])
})
},
beforeRouteLeave(to, from, next) {
if (to.name !== 'detail') {
this.$store.commit('setInclude', [])
this.$destroy()
}
next()
},
寫在routeLeave中出現(xiàn)的問題:
A/B->A/C->D,然后D->A/C緩存這時是生效的,但是再接著繼續(xù)返回到A/B,再走A/C->D,再走D->A/C發(fā)現(xiàn)沒有緩存
beforeRouteLeave(to, from, next) {
if(to.name === 'detail'){
this.$store.commit('setInclude', ['user', 'privateContractPending'])
}else{
this.$store.commit('setInclude', [])
this.$destroy()
}
}
3.keep-alive關(guān)于緩存scrollTop,除非滾動的是window的情況下是可以緩存scrollTop的,其他情況都無法緩存。需要自己記錄。