我正在开发一个小项目,我希望能够使用命名空间来避免具有相同名称的 getter、突变、动作。
如文档中所述,模块必须导入存储,并且映射必须接收到正确模块的路径。
我可以通过省略路径来导入所有内容,但它会抛出重复的 getter 键,如果我指定路径,它会抛出在 mapActions() 中找不到的模块命名空间:
这个错误发生在 getter 和 action 中。
这是我的商店模块:
股票.js
const state = {
stocks: [
{id: 1, name: 'BMW', price: 110},
{id: 2, name: 'Google', price: 200},
{id: 3, name: 'Apple', price: 250},
{id: 4, name: 'Twitter', price: 8}
]
};
const getters = {
getStocks: state => state.stocks
};
const mutations = {
setStocks: (state, data) => state.stocks = data
};
const actions = {
SETSTOCKS: (store, data) => {
store.commit('setStocks', data)
} …Run Code Online (Sandbox Code Playgroud)