wkiwi的博客

default.getters is not a function

发布时间:3个月前热度: 88 ℃评论数:

在非vue文件获取vuex中的值

const state = {
isConnected: true, //设备网络状态 Boolean
}
const getters = {
  getIsConnected(state) {
    return state.isConnected;
  },
};

获取模块app下的 isConnected

store.getters('app/getIsConnected')

default.getters is not a function


修改为

store.getters['app/getIsConnected']


getters在别得地方调用不需要括号

也就是vuex将getters里面的函数对外暴露为一个属性,而不是一个方法


拓展Vue文件内获取vueX中的值

import { mapState, mapActions } from "vuex";

computed:{
    ...mapState("app", {
      isConnected: (state) => state.isConnected,
    }),
  },

getters

手机扫码访问