【发布时间】:2019-08-02 09:33:22
【问题描述】:
我想在 Vue.js 中使用 mapState 从 .js 文件访问我的状态。
我试过了
import { mapState } from 'vuex';
const foo = {
...mapState(['axios']),
};
foo.axios.get('...');
但它不起作用。错误是
TypeError: foo.axios.get is not a function
我应该怎么做才能做到这一点?
我已经搜索过其他问题,但他们从 store.state. ... 访问,而不是使用我想要的 mapState。
【问题讨论】:
-
mapState创建函数。你试过foo.axios().get('...')吗? -
@skirtle 不起作用,
TypeError: this.$store is undefined
标签: javascript vue.js vuejs2 vuex