1 回答

TA貢獻(xiàn)1946條經(jīng)驗(yàn) 獲得超4個(gè)贊
解決方案如下:
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;
}
}
添加回答
舉報(bào)