我需要能够alert从任何Vuex模块更改全局变量的状态。
store / index.js:
export const state = () => ({
alert: null
})
store / child.js:
export const mutations = {
SET_ALERT: function (rootState, alert) {
rootState.alert = alert
}
}
export const actions = {
setalert({commit}){
commit('SET_ALERT', 'warning')
}
}
我想致电setalert并将全局设置store.state.alert为"warning"。目前,store.state.child.alert正"warning"改为设置。