-
存储 this.$store.commit(‘changeValue’,name)
-
取值 this.$store.state.changeValue
dispatch异步操作
-
存储 this.$store.dispatch(‘getlists’,name)
-
取值 this.$store.getters.getlists
3:示例
src/store/index.js
import Vue from “vue”;
import Vuex from “vuex”;
Vue.use(Vuex);
export const store = new Vuex.Store({
// state专门用来保存 共享的状态值
state: {
// 保存登录状态
login: false
},
// mutations: 专门书写方法,用来更新 state 中的值
mutations: {
// 登录
doLogin(state) {
state.login = true;
},
// 退出登录
doLogout(state) {
state.login = false;
}
}
});
src/components/Header.vue
src/components/Login.vue