解決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 },
附上鉤子函數執行順序:
不使用keep-alivebeforeRouteEnter --> created --> mounted --> destroyed
使用keep-alivebeforeRouteEnter --> created --> mounted --> activated --> deactivated再次進入緩存的頁面,只會觸發beforeRouteEnter -->activated --> deactivated 。created和mounted不會再執行。
總結
到此這篇關于Vue中使用keepAlive不緩存問題(已解決)的文章就介紹到這了,更多相關Vue使用keepAlive不緩存內容請搜索好吧啦網以前的文章或繼續瀏覽下面的相關文章希望大家以后多多支持好吧啦網!
相關文章:
1. springcloud alibaba nacos linux配置的詳細教程2. Vue為什么要謹慎使用$attrs與$listeners3. SpringBoot 使用 @Value 注解讀取配置文件給靜態變量賦值4. Java 生成帶Logo和文字的二維碼5. SpringBoot整合MybatisPlus的教程詳解6. 解決在Vue中使用axios POST請求變成OPTIONS的問題7. Spring Boot2發布調用REST服務實現方法8. python 實現圖片修復(可用于去水印)9. Android自定義控件實現方向盤效果10. python中的socket實現ftp客戶端和服務器收發文件及md5加密文件
