2

这是我的vuejs组件,我正在使用基于类的方法。

<template>
    //template body here
</template>

<script>
import Vue from "vue";
import moment from "moment";
import Component from "vue-class-component";
import { State, Action, Mutation, namespace } from "vuex-class";

const homeModule = namespace("../store/modules/list");  //path is OK

export default class List extends Vue {
    @State(state => state.list.apps) items;     //working properly
    @homeModule.Action("fetchItems") fetchItems;    //not working

    mounted() {
        this.fetchItems();
    }

}
</script>

这是我的store/modules/list.js

const state = {
    items: []
};

const mutations = {
    setItems(state, items) {
        state.items = items;
    }
};

const actions = {
    async fetchItems({ commit }) {
        const {data} = //Make a request for fetching the items
        commit('setItems', items);
    }
};

export default {
    namespaced: true,
    state,
    actions,
    mutations
};

现在,我可以从商店中获取商品列表。但无法将操作与组件映射。它显示错误[vuex] module namespace not found in mapActions(): ../store/modules/list/

任何帮助,将不胜感激。谢谢

4

1 回答 1

0

如果你仍然有问题,你正在通过错误的路径

const homeModule = namespace("../store/modules/list");

is 应该是命名空间存储中的路径,而不是文件路径,所以它应该是:

const homeModule = namespace("list");

如果您的模块在listkey下注册

于 2019-12-30T15:24:07.733 回答