安装配置
1. 执行安装命令: npm install vuex
2. 在src目录下新建一个目录store,并在该目录下创建index.js
3. 在index.js中写入以下内容
import { createStore } from 'vuex export default createStore({ state: { }, getters: { mutations: { }, actions: { } })
4. 在main.js中引入store
import { createApp } from 'vue' import App from '. /App.vue' import router from './router' import store from './store' let app = createApp(App) app. use(store) . use(router) . mount(#app)