this.$watch() 的使用(这里可以放在Vue生命周期钩子里):
this.$watch('query', (newQuery) => {
this.$emit('query', newQuery)
})
watch:{}的使用(一个方法):
watch:{
query(newQuery){
this.$emit('query', newQuery)
}
}
本文深入探讨了Vue.js框架中两种监听数据变化的方法:this.$watch()和watch属性。通过具体示例,解释了如何使用这两种方法在数据变化时触发特定操作,如重新渲染或触发事件。
this.$watch() 的使用(这里可以放在Vue生命周期钩子里):
this.$watch('query', (newQuery) => {
this.$emit('query', newQuery)
})
watch:{}的使用(一个方法):
watch:{
query(newQuery){
this.$emit('query', newQuery)
}
}

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