1.那个页面需要将值放到中心数据库就在那个页面的某个vue的生命周期或生命周期 的某个方法 中写入
this.$store.commit('set_userId',this.user_id);
2.store/index.js 需要将传的值接入
//在mutations去改变store中state的状态 ,
//mutations的每个方法有固定的传参顺序,
//参数1 ==>store中state的状态
//参数2 ==> 你传的值 ===this.user_id
import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex)
export default new Vuex.Store({
state: {
userId: null,
},
mutations: {
set_userId: (state, val) => {
state.userId = val;
},
},
})
3.如果,你在别的页面需要使用 中心数据库的值
this.$store.state.userId;
网友评论