采用include+vuex的方式,注意需要缓存的页面,需要声明组件name。 当采用了vue-router的时候,在离开当前页面之前判断下一个页面的路径,然后通过action保存需要缓存的组建name **app.vue **
computed: { ...mapState({ keepAliveName: state => state.wmp.keepAliveName }) }
具体需要换成的页面 name: 'xxx' beforeRouteLeave (to, from, next) { console.log(next) if (to.path === '/main/transRule'|| to.path === '/main/productIntro') { this.saveCachePages(['index','wmpDetail']) } else { this.saveCachePages(['index']) } this.$nextTick(() => { next() }) },