当前位置:网站首页>vue中缓存页面 keepAlive使用

vue中缓存页面 keepAlive使用

2022-06-26 14:47:00 一只金牛座的崽

  1. 在路由中配置
      {
    
        path: '',
        name: 'xx',
        meta: {
     keepAlive: true },
        component: xx
      },
  1. 在App.vue中配置
    <keep-alive>
      <router-view v-if="$route.meta.keepAlive"></router-view>
    </keep-alive>
    <router-view v-if="!$route.meta.keepAlive" :key="key">
    </router-view>
    
    computed: {
    
	    key() {
    
	      return this.$route.path + Math.random();
	    },
	  },
  1. 独有的生命周期
//进入时触发
activated() {
    }
//退出时触发
deactivated() {
    }

keepAlive还支持很多功能,需要自己去查

原网站

版权声明
本文为[一只金牛座的崽]所创,转载请带上原文链接,感谢
https://blog.csdn.net/weixin_43456275/article/details/125397064