Vue2.0中,父组件下字组件A v-model改变emit到父组件,props到子组件B,子组件B watch不到props的第一次变化
字组件A:
this.$watch('query', debounce((newVal) => {
this.$emit('query', newVal)
}, 200))
父组件:
@query="onQueryChange"
onQueryChange(newquery) {
this.currentQuery = newquery
console.log(this.currentQuery)
}
<suggest @select="saveSearch" @listScroll="inputBlur" :query="currentQuery" ref="suggest"></suggest>
字组件B:
watch: {
query(newVal) {
console.log(newVal)
this._search(newVal)
}
第一次变化:
第二次变化:
要加 immediate 为 true 的选项吧?