diff --git a/course/vue2/vuex/heima/src/App.vue b/course/vue2/vuex/heima/src/App.vue index 53492b46bbe9b0cebfdb4c27cbc5e62e6bb173ad..3a45a601fa47a0b39ce47532da904db3b68ae88b 100644 --- a/course/vue2/vuex/heima/src/App.vue +++ b/course/vue2/vuex/heima/src/App.vue @@ -1,22 +1,30 @@ diff --git a/course/vue2/vuex/heima/src/components/Count2.vue b/course/vue2/vuex/heima/src/components/Count2.vue new file mode 100644 index 0000000000000000000000000000000000000000..adf0bb9abdd7ce08523e62091902b6671d277157 --- /dev/null +++ b/course/vue2/vuex/heima/src/components/Count2.vue @@ -0,0 +1,44 @@ + + + + + diff --git a/course/vue2/vuex/heima/src/components/Person.vue b/course/vue2/vuex/heima/src/components/Person.vue new file mode 100644 index 0000000000000000000000000000000000000000..39bcdc7a009802619fda4c637695a7b5501c7229 --- /dev/null +++ b/course/vue2/vuex/heima/src/components/Person.vue @@ -0,0 +1,38 @@ + + + diff --git a/course/vue2/vuex/heima/src/store/index.js b/course/vue2/vuex/heima/src/store/index.js index 0efce327b5e2ad7b1a19a40e996eb253084a4c4e..1a79f8417edb66ef8f5b4723b38aa3e4ffc22a7b 100644 --- a/course/vue2/vuex/heima/src/store/index.js +++ b/course/vue2/vuex/heima/src/store/index.js @@ -1,29 +1,12 @@ +//引入Vue核心库 import Vue from 'vue' +//引入Vuex import Vuex from 'vuex' - +//应用Vuex插件 Vue.use(Vuex) - -export default new Vuex.Store({ - state: { - sum:0 //当前的和 - }, - getters: { - bigSum(state) { - console.log(state) - return state.sum * 10 - } - }, - mutations: { - ADD(state,value){ - console.log("mutations ADD") - state.sum += value - }, - SUBTRACT(state,value){ - console.log("mutations SUBTRACT") - state.sum -= value - } - }, - actions: { + +//准备actions对象——响应组件中用户的动作 +const actions = { addOdd(context,value){ console.log("actions中的addOdd被调用了") if(context.state.sum % 2){ @@ -36,7 +19,40 @@ export default new Vuex.Store({ context.commit('ADD',value) },500) }, - }, - modules: { - } +} +//准备mutations对象——修改state中的数据 +const mutations = { + ADD(state,value){ + state.sum += value + }, + SUBTRACT(state,value){ + state.sum -= value + }, + ADD_PERSON(state,value){ + console.log('mutations中的ADD_PERSON被调用了') + state.personList.unshift(value) + } +} +//准备state对象——保存具体的数据 +const state = { + sum:0, //当前的和 + name:'JOJO', + school:'尚硅谷', + personList:[ + {id:'001',name:'JOJO'} + ] +} +//准备getters对象——用于将state中的数据进行加工 +const getters = { + bigSum(){ + return state.sum * 10 + } +} + +//创建并暴露store +export default new Vuex.Store({ + actions, + mutations, + state, + getters })