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

Vue系列之 computed 和 watch 的区别与使用场景 #64

Open
yuanyuanbyte opened this issue Nov 21, 2021 · 0 comments
Open

Vue系列之 computed 和 watch 的区别与使用场景 #64

yuanyuanbyte opened this issue Nov 21, 2021 · 0 comments

Comments

@yuanyuanbyte
Copy link
Owner

yuanyuanbyte commented Nov 21, 2021

本系列的主题是 Vue,每期讲解一个技术要点。如果你还不了解各系列内容,文末点击查看全部文章,点我跳转到文末

如果觉得本系列不错,欢迎 Star,你的支持是我创作分享的最大动力。

computed 和 watch 的区别与使用场景

computed 是计算属性,依赖已有的响应式数据来计算另一个目标变量,用于响应式数据的复杂逻辑计算处理。

watch 是侦听器,监听到值的变化就会执行相应的回调函数,适用于观测到某个值的变化时 执行复杂的业务逻辑,比如执行异步或开销较大的操作。

使用场景:

当我们需要进行复杂的数值计算或逻辑处理,并且依赖于其它数据时,应该使用 computed,因为可以利用 computed 的缓存特性,避免每次获取值时,都要重新计算;

当我们需要在数据变化时执行异步或开销较大的操作时,使用 watch 是最有用的。

查看全部文章

博文系列目录

  • JavaScript 深入系列
  • JavaScript 专题系列
  • JavaScript 基础系列
  • 网络系列
  • 浏览器系列
  • Webpack 系列
  • Vue 系列
  • 性能优化与网络安全系列
  • HTML 应知应会系列
  • CSS 应知应会系列

交流

各系列文章汇总:https://github.com/yuanyuanbyte/Blog

我是圆圆,一名深耕于前端开发的攻城狮。

weixin

@yuanyuanbyte yuanyuanbyte changed the title Vue系列之 computed 和 watch 的区别和使用场景 Vue系列之 computed 和 watch 的区别与使用场景 Jan 6, 2023
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