Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Typescript 找不到Vuex存储getter函数_Typescript_Vue.js_Vuex_Store_Getter - Fatal编程技术网

Typescript 找不到Vuex存储getter函数

Typescript 找不到Vuex存储getter函数,typescript,vue.js,vuex,store,getter,Typescript,Vue.js,Vuex,Store,Getter,这是我在vuex商店中的收获: const getters= { getUser: (state:any) => {return state.user} }; 在我看来,我确实: <script lang="ts"> ... import {createNamespacedHelpers} from 'vuex' const {mapMutations, mapGetters} = createNamespacedHelpers('user');

这是我在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不是函数。呼叫this.changemail;不过,变异功能正在发挥作用

计算属性不是方法,因此不会被调用。它的行为类似于setter和getter

this.getUser是一个计算属性,其行为更像一个值本身。当您将其放在后面使其调用时,您试图将其视为方法。这是不可能的,因为它不是fn,这就是为什么会出现错误

请参阅此-

Vuex getter/states包含在vue实例的计算属性中,因为它们的工作本身就是返回一个值。然而,突变/动作包含在方法属性中,因为它的任务是执行一个操作示例-发出异步请求并更新状态计算属性不是方法,所以它们不会被调用。它的行为类似于setter和getter

this.getUser是一个计算属性,其行为更像一个值本身。当您将其放在后面使其调用时,您试图将其视为方法。这是不可能的,因为它不是fn,这就是为什么会出现错误

请参阅此-

Vuex getter/states包含在vue实例的计算属性中,因为它们的工作本身就是返回一个值。然而,突变/动作包含在方法属性中,因为它的任务是执行一个操作示例-发出异步请求并更新状态

ok,不知何故这是可行的:this.loggedin=this['getUser'];尝试this.loggedin=this.getUser;它也会起作用,您正试图以某种方式调用fn initiallyok:this.loggedin=this['getUser'];尝试this.loggedin=this.getUser;它也会起作用,您最初尝试调用fn