Skip to content
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

十三、watch和computed的区别以及怎么选用? #13

Open
liwen327 opened this issue Feb 2, 2020 · 0 comments
Open

十三、watch和computed的区别以及怎么选用? #13

liwen327 opened this issue Feb 2, 2020 · 0 comments

Comments

@liwen327
Copy link
Owner

liwen327 commented Feb 2, 2020

区别:
1、定义和语义的区别。
2、处理数据的场景不同:watch适合一个数据影响多个数据,而computed适合多个数据影响一个数据。
3、computed有缓存性。计算所得的值如果没有变化则不重复执行。watch提供了更通用的方法,适合执行异步操作和较大开销操作的情况。

具体怎么选用就看自己项目的业务逻辑了,如果是多个数据影响一个数据,且需要做缓存,则适合用computed,如果是一个多数据影响多个数据且有较大开销的操作则适合用watch。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant