解決Vue中使用keepAlive不緩存問題
1.查看app.vue文件,這個是重點,不能忘記加(我就是忘記加了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.在需要緩存的頁面加入如下代碼
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)入緩存的頁面,只會觸發(fā)beforeRouteEnter -->activated --> deactivated 。created和mounted不會再執(zhí)行。
總結(jié)
到此這篇關(guān)于Vue中使用keepAlive不緩存問題(已解決)的文章就介紹到這了,更多相關(guān)Vue使用keepAlive不緩存內(nèi)容請搜索好吧啦網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持好吧啦網(wǎng)!
相關(guān)文章:
1. Java commons-httpclient如果實現(xiàn)get及post請求2. 一文帶你徹底理解Java序列化和反序列化3. JS中6個對象數(shù)組去重的方法4. Python基于requests庫爬取網(wǎng)站信息5. vscode運行php報錯php?not?found解決辦法6. python中文本字符處理的簡單方法記錄7. PHP laravel實現(xiàn)導(dǎo)出PDF功能8. Python使用Selenium自動進(jìn)行百度搜索的實現(xiàn)9. PHP利用curl發(fā)送HTTP請求的實例代碼10. 資深程序員:給Python軟件開發(fā)測試的25個忠告!

網(wǎng)公網(wǎng)安備