原来写法:vuex3版本
1 2 3 4 5 6 7 8 9 10 |
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:[] },... |
新的写法:vuex4
1 2 3 4 5 6 |
import { createStore } from 'vuex'; export const store = createStore({ state: {...} // other stuff }) |
main.js文件改写
1 2 3 4 5 |
import { createApp } from 'vue'; import { store } from 'path/to/store.js'; const app = createApp({...}) app.use(store); |
可参考:https://github.com/vuejs/vuex/blob/4.0/examples/classic/shopping-cart/store/index.js