解決Vue中使用keepAlive不緩存問(wèn)題
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不緩存問(wèn)題(已解決)的文章就介紹到這了,更多相關(guān)Vue使用keepAlive不緩存內(nèi)容請(qǐng)搜索好吧啦網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持好吧啦網(wǎng)!
相關(guān)文章:
1. Warning: require(): open_basedir restriction in effect,目錄配置open_basedir報(bào)錯(cuò)問(wèn)題分析2. ASP中常用的22個(gè)FSO文件操作函數(shù)整理3. Vue+elementUI下拉框自定義顏色選擇器方式4. React+umi+typeScript創(chuàng)建項(xiàng)目的過(guò)程5. SharePoint Server 2019新特性介紹6. php測(cè)試程序運(yùn)行速度和頁(yè)面執(zhí)行速度的代碼7. php網(wǎng)絡(luò)安全中命令執(zhí)行漏洞的產(chǎn)生及本質(zhì)探究8. ASP的Global.asa文件技巧用法9. ASP中if語(yǔ)句、select 、while循環(huán)的使用方法10. html清除浮動(dòng)的6種方法示例
