我对所有这些都是新手,现在正在学习 Vue。我已经安装了 Vuex,使用导出默认值,然后导入它,但仍然收到此错误 =>
警告在 ./src/store/index.js 中编译有 1 个警告
警告“在‘vuex’中找不到导出‘createStore’
index.js 存储文件
import Vue from 'vue';
import Vuex from 'vuex';
Vue.use(Vuex);
import coachesModule from './modules/coaches/index.js';
const store = new Vuex.Store({
modules: {
coaches: coachesModule
}
});
export default store;
Run Code Online (Sandbox Code Playgroud)
package.json 文件
{
"name": "vue-first-app",
"version": "0.1.0",
"private": true,
"scripts": {
"serve": "vue-cli-service serve",
"build": "vue-cli-service build",
"lint": "vue-cli-service lint"
},
"dependencies": {
"core-js": "^3.6.5",
"vue": "^3.0.0",
"vue-router": "^4.0.0-rc.5",
"vuex": "^3.5.1"
},
"devDependencies": {
"@vue/cli-plugin-babel": "~4.5.0",
"@vue/cli-plugin-eslint": "~4.5.0",
"@vue/cli-service": "~4.5.0",
"@vue/compiler-sfc": "^3.0.0-0",
"babel-eslint": "^10.1.0",
"eslint": "^6.7.2",
"eslint-plugin-vue": "^7.0.0-0"
}
}
Run Code Online (Sandbox Code Playgroud)
卸载 Vue 后使用
npm uninstall -g @vue/cli
Run Code Online (Sandbox Code Playgroud)
并重新安装 Vue 使用
npm install -g @vue/cli@latest
npm i vue vue-router -S
npm install
Run Code Online (Sandbox Code Playgroud)
现在我仍然得到:
INFO Starting development server...
98% after emitting CopyPlugin
WARNING Compiled with 1 warnings 3:56:20 PM
warning in ./src/store/index.js
"export 'default' (imported as 'Vue') was not found in 'vue'
Run Code Online (Sandbox Code Playgroud)
有人可以帮助我吗?
更新。 您使用 vue3 和 vuex3,但您应该使用 vuex4。
你可以尝试使用
const store = new Vuex.Store({
// options
})
Run Code Online (Sandbox Code Playgroud)
代替
const store = createStore({
// options
})
Run Code Online (Sandbox Code Playgroud)
?
根据此文档https://vuex.vuejs.org/guide/#the-simplest-store。