如何在模块vuex js存储中设置全局突变

JavaScript Vue.js

神奇西里泡芙

2020-03-24

我需要能够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"改为设置

第3398篇《如何在模块vuex js存储中设置全局突变》来自Winter(https://github.com/aiyld/aiyld.github.io)的站点

0个回答

问题类别

JavaScript Ckeditor Python Webpack TypeScript Vue.js React.js ExpressJS KoaJS CSS Node.js HTML Django 单元测试 PHP Asp.net jQuery Bootstrap IOS Android