简单Vue
0 1

Vue 中computed和 watch 有哪些关键差异?

【概念释义】

computed:有缓存,依赖变才重算,应纯函数返回值,用于模板衍生数据。watch:监听源执行副作用(请求、localStorage),可访问 old/new,可 async,默认 lazy。

【基础使用】

javascript
computed: {
  fullName() { return this.first + " " + this.last; },
  filtered() { return this.list.filter(x => x.on); },
},
watch: {
  id(val) { this.

登录查看完整 650

回答讨论

暂无讨论,登录后可抢先发言

本题库更多题目(50)