这是我在vuex商店中的吸气剂:
const getters= {
getUser: (state:any) => {return state.user}
};
我认为我愿意:
<script lang="ts">
...
import {createNamespacedHelpers} from 'vuex'
const {mapMutations, mapGetters} = createNamespacedHelpers('user');
export default Vue.extend({
computed: {
...mapGetters([
'getUser'
])
},
methods: {
...mapMutations([
'change'
]),
login() {
this.change(email); //This is a function in the mutations. And this is working
this.loggedin = this.getUser(); // Here it says error
}
}
});
我收到错误:
TypeError: this.getUser is not a function
。不过,对变异函数的调用this.change(email);
正在运行。
computed
属性不是methods
,因此不会被调用。行为类似于setters
和getters
this.getUser
是一个计算属性,其行为更多地类似于一个值本身。当您调用method
之后,尝试将其视为()
。这是不可能的,因为它不是fn
,因此会出现该错误。
请参阅-https://vuejs.org/v2/guide/computed.html#Computed-Caching-vs-Methods