之前vuex1的时候是可以的,但是升级到vuex2之后,就提示找不到getter
<template>
<div>
<h3>Count is {{ theCount }}</h3>
</div>
</template>
<script>
import {mapGetters} from 'vuex'
export default {
computed: {
...mapGetters([
'theCount'
])
}
}
</script>
// getters.js
export const theCount = state => state.count
// store.js
import Vue from 'vue'
import Vuex from 'vuex'
import actions from './actions'
import getters from './getters'
import * as Types from './mutation-types'
Vue.use(Vuex)
const state = {
count: 0
}
const mutations = {
[Types.INCREMENT] (state, amount) {
state.count = state.count + amount;
return true;
},
[Types.DECREMENT] (state, amount) {
if (state.count < amount) return false;
state.count = state.count - amount;
return true;
}
}
export default new Vuex.Store({
actions,
getters,
state,
mutations
})
额。。自己找到问题了。。import actions 和 getters 的时候,没写全。。应该这样