添加依赖
yarn add vuex -S
新建 store/index.js文件
import {createStore} from "vuex"
export default createStore({
state: {
isCollapse: true,
},
mutations: {
updateCollapse(state, payload) {
state.isCollapse = !state.isCollapse
}
}
});
注册到main.js
a组件使用属性
b组件点击更新a组件的数值
注意 commit里面的参数就是
store/index.js
中的
mutations 中的
updateCollapse方法
commit 如果后面再提交参数
那么就是通过payload来进行接受