列表頁進詳情頁返回快取,去其他頁面重新整理(beforeRouteLeave)
阿新 • • 發佈:2022-04-21
列表頁進詳情頁返回快取
在app.vue頁面
<transition name="fade-transform" mode="out-in"> <keep-alive :include="/-keep$/" :max="1"> // max表示只快取一個頁面 <router-view :key="key" /> </keep-alive> </transition> export default { name: "AppMain", // 每個快取的頁面要寫name computed: { key() {return this.$route.path; } } };
列表頁
export default { name: "列表頁名字-keep", activated() { this.getLogList(); // 列表頁資料 }, }
如果去其他頁面快取為清掉,用下面方法
beforeRouteLeave(to, from, next) { // console.log('to', to) // console.log('from', from) if (to.path == "詳情頁" && from.path == "列表頁") { next(); return; } else { this.restFrom() // 清空篩選區域 next(); } },
列表頁進詳情頁返回快取也可用這個方法:https://www.jianshu.com/p/a37684fa55b7 (參照前兩個圖片即可,後面的我感覺寫的有問題)