1 回答
TA贡献1946条经验 获得超4个赞
解决方案如下:
step1
vuex的store里面初始化值,如下操作:
export default new Vuex.Store({
state: {
submitCache : true,
vmRoute : '',
step2
main.js里面判断路由,修改字段值:
router.afterEach(function(transition){
//不缓存
if ( (...) || (...)) {
store.state.submitCache = false;
}
if(transition.path == '/xxx'){
store.state.vmRoute = transition.path;
}else{
store.state.vmRoute = '';
}
})
step3
app.vue如下修改,判断组件缓存逻辑:
<keep-alive>
<router-view v-if="isCache && vmRouter"></router-view>
</keep-alive>
<router-view v-if="!isCache || !vmRouter"></router-view>
拿到所需字段:
computed: {
isCache : function(){
return this.$store.state.submitCache;
},
vmRouter: function(){
return this.$store.state.vmRoute;
}
}
添加回答
举报