如何解决Error app.use(store) is not a function
How to solve Error app.use(store) is not a function
我正在尝试使用 vuex 存储,所以我创建了包含此代码的文件 store.js
import { createApp } from 'vue'
import Vuex from "vuex"
const app = createApp;
app.use(Vuex)
const store = new Vuex.Store({
});
export default store;
这是main.js
import 'bootstrap/dist/css/bootstrap.css'
import { createApp } from 'vue'
import App from './App.vue'
import router from './router'
import store from './store/store'
const app = createApp(App);
app.use(router)
app.use(store)
app.mount('#app')
这是package.json我不知道为什么即使我安装了vuex也没有出现
{
"name": "PhoSettings",
"version": "0.1.0",
"private": true,
"scripts": {
"serve": "vue-cli-service serve",
"build": "vue-cli-service build",
"lint": "vue-cli-service lint"
},
"dependencies": {
"axios": "^0.20.0-0",
"bootstrap": "^4.5.3",
"core-js": "^3.7.0",
"vue": "^3.0.2",
"vue-loader-v16": "npm:vue-loader@^16.0.0-alpha.3",
"vue-router": "^4.0.0-rc.5"
},
"devDependencies": {
"@vue/cli-plugin-babel": "^4.5.9",
"@vue/cli-plugin-eslint": "^4.5.9",
"@vue/cli-service": "^4.5.9",
"@vue/compiler-sfc": "^3.0.2",
"babel-eslint": "^10.1.0",
"eslint": "^6.8.0",
"eslint-plugin-vue": "^7.1.0"
},
"eslintConfig": {
"root": true,
"env": {
"node": true
},
"extends": [
"plugin:vue/vue3-essential",
"eslint:recommended"
],
"parserOptions": {
"parser": "babel-eslint"
},
"rules": {}
},
"browserslist": [
"> 1%",
"last 2 versions",
"not dead"
]
}
然后出现以下错误:未捕获类型错误:app.use 不是函数
由于您使用的是 vue 3,因此您应该使用以下命令安装 vuex
v4:
npm install vuex@next --save
然后像这样使用它:
import { createStore } from 'vuex'
// Create a new store instance.
const store = createStore({
})
export default store
main.js
:
import 'bootstrap/dist/css/bootstrap.css'
import { createApp } from 'vue'
import App from './App.vue'
import router from './router'
import store from './store/store'
const app = createApp(App);
app.use(router)
app.use(store)
app.mount('#app')
我正在尝试使用 vuex 存储,所以我创建了包含此代码的文件 store.js
import { createApp } from 'vue'
import Vuex from "vuex"
const app = createApp;
app.use(Vuex)
const store = new Vuex.Store({
});
export default store;
这是main.js
import 'bootstrap/dist/css/bootstrap.css'
import { createApp } from 'vue'
import App from './App.vue'
import router from './router'
import store from './store/store'
const app = createApp(App);
app.use(router)
app.use(store)
app.mount('#app')
这是package.json我不知道为什么即使我安装了vuex也没有出现
{
"name": "PhoSettings",
"version": "0.1.0",
"private": true,
"scripts": {
"serve": "vue-cli-service serve",
"build": "vue-cli-service build",
"lint": "vue-cli-service lint"
},
"dependencies": {
"axios": "^0.20.0-0",
"bootstrap": "^4.5.3",
"core-js": "^3.7.0",
"vue": "^3.0.2",
"vue-loader-v16": "npm:vue-loader@^16.0.0-alpha.3",
"vue-router": "^4.0.0-rc.5"
},
"devDependencies": {
"@vue/cli-plugin-babel": "^4.5.9",
"@vue/cli-plugin-eslint": "^4.5.9",
"@vue/cli-service": "^4.5.9",
"@vue/compiler-sfc": "^3.0.2",
"babel-eslint": "^10.1.0",
"eslint": "^6.8.0",
"eslint-plugin-vue": "^7.1.0"
},
"eslintConfig": {
"root": true,
"env": {
"node": true
},
"extends": [
"plugin:vue/vue3-essential",
"eslint:recommended"
],
"parserOptions": {
"parser": "babel-eslint"
},
"rules": {}
},
"browserslist": [
"> 1%",
"last 2 versions",
"not dead"
]
}
然后出现以下错误:未捕获类型错误:app.use 不是函数
由于您使用的是 vue 3,因此您应该使用以下命令安装 vuex
v4:
npm install vuex@next --save
然后像这样使用它:
import { createStore } from 'vuex'
// Create a new store instance.
const store = createStore({
})
export default store
main.js
:
import 'bootstrap/dist/css/bootstrap.css'
import { createApp } from 'vue'
import App from './App.vue'
import router from './router'
import store from './store/store'
const app = createApp(App);
app.use(router)
app.use(store)
app.mount('#app')