一、最近用vue作前端項目,從查詢頁面進入詳情頁時,返回頁面須要保留上次的查詢條件,表格當前頁數。
二、從其餘菜單進去,不須要緩存,要保持頁面的初始狀態。
基於上面兩種狀況,我打算用vue中的keep-alive來緩存頁面。前端
. 用vue的內置組件keep-alive來緩存列表頁面,再路由出口渲染組件時配置:vue
<keep-alive> <router-view v-if="$route.meta.keepAlive"></router-view> </keep-alive> <router-view v-if="!$route.meta.keepAlive"></router-view>
{ name:'borrow', path:'/borrow', component:borrow, meta: { keepAlive:true, isBack: true, }, }
beforeRouteEnter(to, from, next) { if (from.path == "/addborrow") { to.meta.isBack = true; } else { to.meta.isBack = false; } next(); },
activated() { if (!this.$route.meta.isBack) { this.handleClear('queryForm');/*清空查詢條件*/ }else{ this.$route.meta.isBack = false; this.getBorrowList();/*列表從新加載*/ } },