A组件(事件操作):
methods: {// 收缩菜单menuShrink () {this.iscollapse = !this.iscollapse;this.$store.state.iscollapse = this.iscollapse;},}
B组件(监听state某值的变化做一些逻辑代码)
- 先用computed(计算属性)拿到state值
- 再用watch去监听
computed: {iscollapse () {return this.$store.state.iscollapse}},watch: {iscollapse (newData) {if (!newData) {this.tabsWidth = `max-width:${window.innerWidth - 200}px`;} else {this.tabsWidth = `max-width:${window.innerWidth - 65}px`;}}},
end~~~
如有错误或观点不一致的请评论留言共同讨论,本人前端小白一枚,根据自己实际项目遇到的问题进行总结分享,谢谢大家的阅读!