为什么 Vuex 在模块上使用 mapState 时会抛出错误

时间:2020-12-23 04:26:12

标签: vue.js vuex vuex-modules

如果我这样做

computed: {
  authors() {
      return store.state.author.authors;
  }
},

它返回作者数据,但如果我这样做

computed: {
  ...mapState({
      authors: state => state.author.authors
  })
},

它抛出错误为 TypeError: Cannot read property 'state' of undefined

有什么想法吗?

这是我的根存储代码(index.js)

import Vue from "vue";
import Vuex from "vuex";
Vue.use(Vuex);

import author from "./author";

export default new Vuex.Store({
    strict: true,
    modules: {
        author
    }
});

这里是我如何包含在组件中

import store from "../store";
import { mapState } from "vuex";

0 个答案:

没有答案
相关问题