store/index.js
state{
drawerStatus: true,
}
Dashboard.vue
data() {
return {
drawer: true,
};
},
watch: {
"$store.state.drawerStatus"() {
this.drawer = this.$store.state.drawerStatus;
}
}
本文探讨了Vue应用中使用Vuex进行状态管理的情况,具体展示了如何在`Dashboard.vue`组件中监听并响应`store/index.js`中全局`drawerStatus`状态的变化,实现组件内部`drawer`状态的同步更新,从而确保UI与全局状态的一致性。
store/index.js
state{
drawerStatus: true,
}
Dashboard.vue
data() {
return {
drawer: true,
};
},
watch: {
"$store.state.drawerStatus"() {
this.drawer = this.$store.state.drawerStatus;
}
}
4157
1728

被折叠的 条评论
为什么被折叠?