初始化
This commit is contained in:
@@ -0,0 +1,15 @@
|
||||
/*
|
||||
* */
|
||||
|
||||
|
||||
import Vuex from 'vuex'
|
||||
|
||||
export default (Vue) => {
|
||||
Vue.use(Vuex);
|
||||
|
||||
const store = require("./store")
|
||||
return {
|
||||
name : "store",
|
||||
value: store.default
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
import Vuex from 'vuex'
|
||||
|
||||
const state = {
|
||||
count: 1
|
||||
}
|
||||
|
||||
const mutations = {
|
||||
|
||||
SET_ADD_COUNT : (state) => {
|
||||
state.count++
|
||||
},
|
||||
SET_SUBTRACT_COUNT: (state) => {
|
||||
state.count--
|
||||
}
|
||||
}
|
||||
|
||||
const actions = {
|
||||
// 加
|
||||
add({commit}) {
|
||||
commit('SET_ADD_COUNT')
|
||||
},
|
||||
// 减
|
||||
subtract({commit}) {
|
||||
commit('SET_SUBTRACT_COUNT')
|
||||
}
|
||||
|
||||
}
|
||||
const store = new Vuex.Store({
|
||||
modules: {
|
||||
//封装的存放state下count的方法
|
||||
app: {
|
||||
// namespaced: true,
|
||||
state,
|
||||
mutations,
|
||||
actions
|
||||
}
|
||||
}
|
||||
})
|
||||
export default store
|
||||
Reference in New Issue
Block a user