vue中使用vuex缓存组件

在app.vue中,使用keep-alive,它的属性include,来缓存组件

在这里插入图片描述

配合使用vuex,来添加需要缓存的组件

在这里插入图片描述

在需要做缓存的组件内使用
1,引入vuex
2,触发mutations 里的 addCachePage 方法,
this.$store.commit(‘addCachePage’, ‘test’);
3,注意:组件的name:‘test’必须带上,

4,移除缓存触发mutations 里的 removeCachePage方法,
this.$store.commit(‘removeCachePage’, ‘test’) 即可

猜你喜欢

转载自blog.csdn.net/weixin_45108907/article/details/108024127
今日推荐