vuex模組開發
阿新 • • 發佈:2018-12-03
- 使用vuex模組開發
cnpm i vuex -D
import vuex from "vuex"
Vue.use("vuex")
- main.js
import store form './store'
new Vue({
el: '#app',
router,
store,
components: { App },
template: '<App/>'
})
- src/store
import Vue from "vue"; import Vuex from 'vuex'; import a from './modules/a'; Vue.use(Vuex) let store = new Vuex.Store({ modules:{ a:a } }) export default store
- src/store/modules/a
const a = {
state: {
msg: "hahah"
},
mutations: {
newMsg(state, msg) {
state.msg = msg
}
},
actions: {
newMsg(context, msg) {
context.commit("newMsg", msg)
}
}
}
export default a