vue中keep-alive使用时,注意要点

时间:2024-10-11 11:07:44
 <keep-alive exclude="QRCode,NewsInfor,VipRecordDetail">
<router-view></router-view>
</keep-alive>
注意:QRCode时组件的名字,一定不能漏
A页面-->B页面,B-->A页面
B-->C页面 C-->B
其中B退回到A页面,再进入B页面,需要请求数据,
B页面到C页面,C页面退回B页面,不需要请求数据 例子:路由:{
path: '/VipRecord',
name: 'VipRecord',
component: () => import( /* webpackChunkName: "oldrecord" */ './views/vip/vipRecord/VipRecord.vue'),
meta:{
isCache:false
}
},
B页面:
export default {
name: "VipRecord",
beforeRouteEnter(to, from, next) {
if (from.name == "HasBind") {
to.meta.isCache=true;
}
else if(from.name == "VipRecordDetail")
{
to.meta.isCache=false;
}
next();
},
activated(){
if(this.$route.meta.isCache)
{
this.hdrData=[]; //清空数据
this.getyear();
}
},