app.vue文件(路由切换文件)
<keep-alive :include="pageArr"> <router-view></router-view> </keep-alive>
data () { return { pageArr: [ 'sourceLists', //要缓存的路由名称 'manageList' //要缓存的路由名称
],
}
要缓存的页面文件activated() { this.fetchData(); },
//activated钩子
//路由离开当前要缓存的页面的操作beforeRouteLeave (to, from, next) { // 导航离开该组件的对应路由时调用 // 可以访问组件实例 `this` if (to.path !== '/literature/pool/detail') { //初始化筛选条件项 this.formInline.name = ''; this.formInline.roleId = 0; this.pageSize = 10; this.pageNum = 1; this.current = 1; this.total = 0; } next(); },