在我的vue前端,我尝试设置Vuex。在我的商店页面上(在商店目录内,文件名为index.js)使用VUE3.0的.Im当我运行代码时,我得到了Cannot read property 'use‘of undefined On Vue.use(Vuex)行
这是代码的一部分
import Vue from "vue";
import Vuex from "vuex";
import Api from "../services/api";
Vue.use(Vuex);//here i get the error
export default new Vuex.Store({
state:{
articles:[]
},...发布于 2020-09-08 02:28:25
你需要使用Vuex 4来兼容Vue3,Vuex4引入了一些突破性的变化,其中之一就是如何初始化存储。基本上,您现在不再使用new Vuex.Store,而是使用createStore来创建商店对象,并且不再需要在store.js中使用Vue.use(Vuex)。
import { createStore } from 'vuex';
export const store = createStore({
state: {...}
// other stuff
})在您的main.js文件中:
import { createApp } from 'vue';
import { store } from 'path/to/store.js';
const app = createApp({...})
app.use(store);https://stackoverflow.com/questions/63782476
复制相似问题