1.新建一个文件夹,新建js文件
js文件内容
// 页面路径:store/index.js
import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex); //vue的插件机制
//Vuex.Store 构造器选项
const store = new Vuex.Store({
state: { //存放状态
oldMainId:"",
},
mutations: {
setOldMainId(state, oldMainId) {
state.oldMainId = oldMainId
},
}
})
export default store
2.页面调用
this.$store.commit('setOldMainId', this.careCenterItem.deptId)
将你需要的值存入的缓冲中
3.在你需要调用的地方使用
this.oldMainId = this.$store.state.oldMainId;