0
点赞
收藏
分享

微信扫一扫

Vue官方文档(51): vuex中模块化的用法


一、定义store

import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

const moduleA = {
state: () => ({
count1: 1,
count2: 2
}),
mutations: {
},
actions: { },
getters: { }
}

const moduleB = {
state: () => ({
count1: 30,
count2: 40
}),
mutations: {

},
actions: { }
}

const store2 = new Vuex.Store({
modules: {
a: moduleA,
b: moduleB
}
})
export default store2;

二、引入store,此处也可以改成全局引入。并使用。

import store2 from './store/store2'

alert(store2.state.a.count1);
alert(store2.state.b.count2);


举报

相关推荐

0 条评论