【发布时间】:2021-06-17 08:10:10
【问题描述】:
我正在 Nuxt 中创建一个带有 Vuex 状态管理的应用程序。问题是我想创建带有函数的 js 文件,我将把它导入到我的 Vue 文件中。我需要访问该文件中的商店。
在 functions.js 中,我想使用 import store from "@/store" 导入商店,但 store 给了我空对象。当我做import store from "@/store/dice.js",这是我想要访问的商店它返回未定义并在控制台中我得到信息:"export 'default' (imported as '$store') was not found in '~/store/dice'
@/store/index.js 为空。
@/store/dice.js 的结构类似于 Nuxt 教程:
export const state = () => ({
list: []
})
export const mutations = {
add(state, text) {
state.list.push({
text,
done: false
})
},
remove(state, { todo }) {
state.list.splice(state.list.indexOf(todo), 1)
},
toggle(state, todo) {
todo.done = !todo.done
}
}
谁能帮忙?
【问题讨论】: