watch
基础语法
通过 watch
字段
export default {
// ...
watch: {
key: {
handler() {},
flush: 'post'
}
}
}
通过 this.$watch()
在生命周期中创建
export default {
created() {
this.$watch('question', (newQuestion) => {
// ...
})
}
}
https://cn.vuejs.org/guide/essentials/watchers.html#callback-flush-timing
字段 | 说明 | 备注 |
---|---|---|
immediate: bool | 强制立即执行回调 | |
deep: bool | 是否深度监听 | |
flush: String 'post' | 回调的触发时机 |