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 、methods、watch 的区别 #89

Open
lovelmh13 opened this issue Jun 24, 2021 · 0 comments
Open

Vue 中的 computed 、methods、watch 的区别 #89

lovelmh13 opened this issue Jun 24, 2021 · 0 comments

Comments

@lovelmh13
Copy link
Owner

lovelmh13 commented Jun 24, 2021

  1. computed 是属性,具有缓存功能,不需要每次都计算;methods 是方法,每次需要执行函数来重新得到结果,即使值没有变化。
  2. computed 可以拿到 data 的属性,但是 data 不能拿到 computed 的值,因为源码里 computed 在 data 之后生成。
  3. computed 在DOM 加载后直接执行,methods 需要触发条件。
  4. watch 监听的是已经在实例上的数据, computed 计算的是一个属性本身,这个属性就在 vue 实例上

https://zhuanlan.zhihu.com/p/55440112

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