- npm install vuex --save
- 在main文件中引入使用
import store from ‘./store/index.js’
import Vuex from ‘vuex’
Vue.use(Vuex) - main.js文件中
new Vue({
el: ‘#app’,
router,
store, //加入vuex
components: { App },
template: ‘’
}) - 创建store ->index.js
import Vue from ‘vue’;
import Vuex from ‘vuex’;
Vue.use(Vuex);
export default new Vuex.Store({
state:{ //存储数据
option:[]
},
mutations:{ //处理数据
},
getters:{ //数据包装
},
})
vuex的引用
最新推荐文章于 2023-02-25 21:35:39 发布
本文介绍了如何在Vue项目中安装和使用Vuex。首先通过npm安装Vuex,然后在main.js文件中引入并启用Vuex,接着在创建的store/index.js文件中定义state、mutations和getters来管理应用的状态。
摘要由CSDN通过智能技术生成