简体   繁体   English

Vuex动态模块未命名空间

[英]Vuex dynamic modules are not being namespaced

I'm working with a modular vue application that registers the modules at compile time. 我正在使用在编译时注册模块的模块化vue应用程序。 Please see the code below - 请参见下面的代码-

app.js app.js

import store from './vue-components/store';

var components = {
    erp_inventory: true,
    erp_purchase: true,
};

// Inventory Module Components
if (components.erp_inventory) {
    // erp_inventory.
    store.registerModule('erp_inventory', require('./erp-inventory/vue-components/store'));
    // erp_inventory/product_search_bar
    store.registerModule([ 'erp_inventory', 'product_search_bar' ], require('./erp-inventory/vue-components/store/products/search-bar'));
}

./erp-inventory/vue-components/store/index.js ./erp-inventory/vue-components/store/index.js

export default {
    namespaced: true,
    state() {
        return {};
    },
    getters: {},
    actions: {}
}

./erp-inventory/vue-components/store/products/search-bar/index.js ./erp-inventory/vue-components/store/products/search-bar/index.js

export default {
    namespaced: true,
    state() {
        return {
            supplier_id
        };
    },
    getters: {
        supplier_id: (state) => {
            return state.supplier_id;
        }
    },
    actions: {
        set_supplier_id({ commit }, supplier_id) {
            commit('set_supplier_id', supplier_id);
        }
    },
    mutations: {
        set_supplier_id(state, supplier_id) {
            state.supplier_id = supplier_id;
        }
    }
}

When I use context.$store.dispatch('erp_inventory/product_search_bar/set_supplier_id', e.target.value, {root:true}); 当我使用context.$store.dispatch('erp_inventory/product_search_bar/set_supplier_id', e.target.value, {root:true}); to dispatch the action in search-bar/index.js, vue is unable to find the namespace stating [vuex] unknown action type: erp_inventory/product_search_bar/set_supplier_id 要在search-bar / index.js中分派操作,vue无法找到说明[vuex] unknown action type: erp_inventory/product_search_bar/set_supplier_id的名称空间[vuex] unknown action type: erp_inventory/product_search_bar/set_supplier_id

I've read the documentation of vuex and dynamic modules and even though I've set namespaced: true, in each store, this problem persists. 我已经阅读了vuex和动态模块的文档,即使我已将namespaced: true,设置为namespaced: true,在每个商店中,此问题仍然存在。 After dumping the store of my app I found that namespaced was never being set for registered modules (see image below). 转储我的应用程序商店后,我发现从未为注册的模块设置namespaced (请参见下图)。

命名空间为假

Unless I'm doing something wrong, could it be a bug? 除非我做错了,否则可能是个错误?

您必须使用require(....)。default,否则您将无法从ES6模块文件获得默认的导出pc,而是通过包装它的webpack来获取对象。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM