-
-
Notifications
You must be signed in to change notification settings - Fork 3.3k
[vue] watch和计算属性有什么区别? #264
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
watch: 看你怎么做, 然后做出某些相应的调整 |
|
watch可以深度监听复杂对象的变化; |
还可以问methods、watch、computed区别 |
我认为computed:1、它是依靠依赖项的变化,来对自己做出改变 2、它具有缓存 |
https://cn.vuejs.org/v2/guide/computed.html 这里的demo 说的很清楚了,能不用watch就不用watch, watch一般用在你要监听的属性与你要使用的属性没有太多关联的时候,一般在异步时使用 |
主要区别: |
1、定义:watch是侦听属性、computed是计算属性 |
|
1 similar comment
|
计算属性是一个新的属性,其属性值依赖于其他属性,监听属性可以监听data属性或者computed计算属性中,是对于这些属性的监听,也就是这些属性一旦改变就执行回调函数,可以处理异步,但是计算属性只能是同步的。计算属性是可以缓存的。 |
在Vue中,watch 和计算属性(computed)都用于监视数据的变化并触发相应的操作 区别计算属性(computed):计算属性是基于依赖的数据进行计算得出的一个新值。 Watch(侦听器): 总结来说,计算属性适合处理基于数据的实时计算逻辑,它会根据依赖的数据进行缓存和自动更新。而 Watch 适合处理数据变化后需要执行异步操作、复杂逻辑或依赖多个数据的情况。选择使用哪种方式取决于具体的业务需求和代码结构的设计。 |
[vue] watch和计算属性有什么区别?
The text was updated successfully, but these errors were encountered: