const searchString=ref('');
watch(searchString, () => {
//perform a search
})
Deep Watch是必须检测更改的必要条件:
const filters=ref({name:'',price:'',country:''});
watch(filters, () => {
//perform a filter operation depending on filter options
}, { deep: true });
在第二个示例中,您需要将 efferters.value 设置为新对象,因为您不使用 deep> deep
Deep watch is for tracking changes on an objects properties. Obviously it has a performance impact. Most of the time simple data types are watched instead of objects. So enabling it by default makes no sense.
So if you do not need to track changes of an objects properties you do not need to use deep watch.
Shallow use for an object is only makes sense if the object assignment changes totaly.
No need for deepWatch:
const searchString=ref('');
watch(searchString, () => {
//perform a search
})
Deep watch is necessery to detect changes:
const filters=ref({name:'',price:'',country:''});
watch(filters, () => {
//perform a filter operation depending on filter options
}, { deep: true });
In the second example you need to set filters.value to a new object each time is you do not use deep
发布评论
评论(1)
深度手表用于跟踪对象属性的更改。显然,它具有性能影响。在大多数情况下,观看简单数据类型而不是对象。因此,默认情况下启用它是没有道理的。
因此,如果您不需要跟踪对象属性的更改,则无需使用深度手表。
仅当对象分配总共更改时,对象的浅使用才有意义。
在第二个示例中,您需要将
efferters.value
设置为新对象,因为您不使用deep> deep
Deep watch is for tracking changes on an objects properties. Obviously it has a performance impact. Most of the time simple data types are watched instead of objects. So enabling it by default makes no sense.
So if you do not need to track changes of an objects properties you do not need to use deep watch.
Shallow use for an object is only makes sense if the object assignment changes totaly.
In the second example you need to set
filters.value
to a new object each time is you do not usedeep