解決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. python爬蟲實戰(zhàn)之制作屬于自己的一個IP代理模塊2. python 利用toapi庫自動生成api3. Android Studio設(shè)置顏色拾色器工具Color Picker教程4. HTML 絕對路徑與相對路徑概念詳細(xì)5. python實現(xiàn)PolynomialFeatures多項式的方法6. python實現(xiàn)在內(nèi)存中讀寫str和二進(jìn)制數(shù)據(jù)代碼7. IntelliJ IDEA設(shè)置默認(rèn)瀏覽器的方法8. Java程序的編碼規(guī)范(6)9. Spring如何使用xml創(chuàng)建bean對象10. python實現(xiàn)讀取類別頻數(shù)數(shù)據(jù)畫水平條形圖案例
