【问题标题】:[vuex]unknown action type: getPackagingList[vuex]未知动作类型:getPackagingList
【发布时间】:2021-09-13 10:33:50
【问题描述】:

我正在使用带有命名空间的 vuex,我为 vuex 创建了 à store,当我调用操作时出现错误 [vuex] 未知操作类型:getPackagingList,我检查了所有内容的拼写错误,但没有结果: 商店(index.js):

import Vue from 'vue'
import Vuex from 'vuex'
import state from './state';
import * as getters from './getters';
import * as mutations from './mutations';
import * as actions from './actions';
import packaging from './modules/item/packaging'
Vue.use(Vuex);
export default new Vuex.Store({
    namespaced: true,
    state,
    getters,
    actions,
    mutations,
    modules: {  
            packaging,
    }
})

index.js(包装的):

import state from './state';
import * as getters from './getters';
import * as mutations from './mutations';
import * as actions from './actions';
export default {
    namespaced: true,
    state,
    getters,
    actions,
    mutations
};

actions.js:

import axios from 'axios'
import Vue from 'vue'
export const getPackagingList = ({ commit }) => {
        axios.get("product/packaging/index", {
          headers: {
            "Content-Type": "application/json",
            //  withCredentials: true //sent with cookie
            Authorization: "Bearer " + Vue.$cookies.get("jwt"),
          },
        })
        .then(res => {
            commit("SET_PACKAGING", res.data);
        })
  };

mutations.js

export const SET_PACKAGING = (state, packagingList) => {
    state.packagingList= packagingList;
  };

state.js

export default {
    packagingList:[],
    packagingId : null,
}

对 mycomponent.vue 调用操作:

mounted() {
    this.getPackagingList();
}
methods: {
    ...mapActions(['getPackagingList']),
}

【问题讨论】:

    标签: vuejs2 vuex


    【解决方案1】:

    试试这个

    mounted() {
        this.getPackagingList();
    }
    methods: {
        ...mapActions('packaging', ['getPackagingList']),
    }
    

    【讨论】:

      猜你喜欢
      • 2022-01-02
      • 2019-10-28
      • 2021-06-26
      • 2020-09-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-01-18
      相关资源
      最近更新 更多