keepAlive缓存的使用,监听路由

1.缓存组件:

组件路由routers.js页面添加keepAlive:true

{
path: 'supplierList',
name: 'supplierList',
meta: {
title: '供应商列表',
keepAlive: true
},
component: () => import('@/view/data-base/supplierList')
},
supplierList.vue组件页面不需要做更改
如果想刷新页面可以添加监听路由事件
watch: {
 $route(to, from) {
 if (to.name === "supplierList") {//如果进入的页面name是supplierList
//获取后端数据渲染当前页面  也就是刷新页面
this.queryFun(true);
}
 }
}
 
原文地址:https://www.cnblogs.com/wssdx/p/11162483.html