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的区别 #39

Open
wohaofang opened this issue Jul 31, 2020 · 0 comments
Open

vue中computed和watch的区别 #39

wohaofang opened this issue Jul 31, 2020 · 0 comments
Labels

Comments

@wohaofang
Copy link
Owner

计算属性computed:

  1. 支持缓存,只有依赖的数据发声改变,才会重新进行计算
  2. 不支持异步
  3. computed属性值会默认走缓存,计算属性是基于它们的响应式依赖进行缓存的
  4. 如果computed属性值是函数,那他默认会走get方法,函数的返回值就是属性的属性值;在computed中的,属性都有一个get和一个set方法,当数据变化时,调用set方法。

监听属性watch:

  1. 不支持缓存,数据变,直接回触发对应操作;
  2. watch支持异步;
  3. 监听的函数接收两个参数,第一个是新值,第二个是之前的值;
  4. 当一个属性发声变化时,会执行对应操作,一对多;
  5. 监听数据必须是data 声明的或者props 中的数据
@wohaofang wohaofang added the vue label Aug 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant