【发布时间】:2018-09-21 01:14:39
【问题描述】:
我正在开发带有 2 个组件的 VueJS2。
期望的行为:每次在一个组件中触发一个方法时,我想在另一个组件中触发一个方法。
我认为 watch 和 $refs 是我需要的。这就是它的样子:
watch: {
'this.$refs.component1.method1': () => {
console.log('TRIGGERED method1')
this.$refs.component2.method1()
},
'this.$refs.component1.method2': () => {
console.log('TRIGGERED metdod2')
this.$refs.component2.method2()
}
很遗憾,这不起作用。是否可以观看方法调用?
【问题讨论】:
标签: vue.js vuejs2 vue-component watch