找不到Vuex商店吸气剂功能

这是我在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);正在工作。

lovepiaohan 回答:找不到Vuex商店吸气剂功能

computed属性不是methods,因此不会被调用。行为类似于settersgetters

this.getUser是一个计算属性,其行为更多地类似于一个值本身。在调用之后放置method时,您尝试将其视为()。这不可能,因为不是fn才导致出现该错误。

请参阅-https://vuejs.org/v2/guide/computed.html#Computed-Caching-vs-Methods

Vuex getters/states包含在vue computed的{​​{1}}属性中,因为其工作本身就是返回instances。但是value会包含在mutations/actions属性中,因为它的工作是methods一个操作示例-提出perform请求并更新async

本文链接:https://www.f2er.com/3008752.html

大家都在问