解決Vue中使用keepAlive不緩存問題
1.查看app.vue文件,這個(gè)是重點(diǎn),不能忘記加(我就是忘記加了keep-alive)
<template> <div> <keep-alive><router-view v-if='$route.meta.keepAlive'></router-view> </keep-alive> <router-view v-if='!$route.meta.keepAlive'></router-view> </div></template>
2.查看router.js
{ path:’/loanmessage’, component:loanmessage, name:’loanmessage’, meta: { keepAlive: true, //代表需要緩存 isBack: false, },
3.在需要緩存的頁(yè)面加入如下代碼
beforeRouteEnter(to, from, next) { if (from.name == ’creditInformation’ || from.name == ’cityList’) { to.meta.isBack = true; } next();},activated() { this.getData() this.$route.meta.isBack = false this.isFirstEnter = false },
附上鉤子函數(shù)執(zhí)行順序:
不使用keep-alivebeforeRouteEnter --> created --> mounted --> destroyed
使用keep-alivebeforeRouteEnter --> created --> mounted --> activated --> deactivated再次進(jìn)入緩存的頁(yè)面,只會(huì)觸發(fā)beforeRouteEnter -->activated --> deactivated 。created和mounted不會(huì)再執(zhí)行。
總結(jié)
到此這篇關(guān)于Vue中使用keepAlive不緩存問題(已解決)的文章就介紹到這了,更多相關(guān)Vue使用keepAlive不緩存內(nèi)容請(qǐng)搜索好吧啦網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持好吧啦網(wǎng)!
相關(guān)文章:
1. jsp實(shí)現(xiàn)textarea中的文字保存換行空格存到數(shù)據(jù)庫(kù)的方法2. Python matplotlib 繪制雙Y軸曲線圖的示例代碼3. 利用ajax+php實(shí)現(xiàn)商品價(jià)格計(jì)算4. JSP頁(yè)面實(shí)現(xiàn)驗(yàn)證碼校驗(yàn)功能5. asp知識(shí)整理筆記4(問答模式)6. java 優(yōu)雅關(guān)閉線程池的方案7. python selenium 獲取接口數(shù)據(jù)的實(shí)現(xiàn)8. 詳解idea中web.xml默認(rèn)版本問題解決9. ASP實(shí)現(xiàn)加法驗(yàn)證碼10. jsp EL表達(dá)式詳解
