在vue2中,要用vuex的3版本
npm#
npm install vuex@3 --save
Yarn#
yarn add vuex@3 --save
在vue3中,要用vuex的4版本
创建 /store/index.js
文件
// 创建 /store/index.js 文件
import Vue from 'vue' //引入Vue
import Vuex from 'vuex' //引入Vuex
Vue.use(Vuex) //应用
export default new Vuex.Store({
actions:{}, //接受用户的事件
mutations:{}, //操作state中的数据
state:{}, //存放共享的数据
})
/ main.js
import store from './store/index.js'
new Vue({
el:"#app",
render: h => h(App),
store:store
})