getters.js
const getters={
addCount : function (state) {
return state.count += 1000
}
};
export default getters;
store.js
/**
- vux
- 状态管理器
- 管理项目中共用的属性
*/
import Vue from 'vue'
import Vuex from 'vuex'
import state from './state'
import mutations from './mutations'
import getters from './getters'
import actions from './action'
Vue.use(Vuex);
export default new Vuex.Store({
state,
mutations,
getters,
actions
})
xxx.vue 模板文件
import store from '../../../vuex/store'
import {mapState,mapMutations,mapGetters} from 'vuex'
computed : {
...mapGetters(['addCount']),
...mapState(["count"]),
}
getters 中并没有给count 加1000,是我哪里写错了吗
需要将store挂载到app上
import store from './vuex/store'
new Vue({
el: '#app',
router,
store,
template: '<App/>',
components: { App }
})