chenhuiYj / chenhuiYj/note

vue 的 computed, watch ,filters 有什么区别

Open
#3 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
HTML
Stars
6
Forks
0
PR merge metrics
No merged PRs in 30d

Description

computed

特性:依赖 Vue 实例,在某一个实例中使用,不接受额外的参数,依赖于 data 里面的值,有缓存机制,可以减少页面调用次数,默认只读,但是可以设置set进行写值。作为实例的一个属性使用。

适用场景:一个属性的值,收到多个属性的值影响的时候。比如购物车的商品总数,总价,全选功能,

watch

特性:依赖 Vue 实例,在某一个实例中使用,回调接收两个参数,一个newVal,一个oldVal,只能监听data里面的值,无缓存机制。

适用场景:一个属性的值的改变会影响多个属性的值的时候。比如根据搜索关键词,给出对应的搜索结果和推荐结果,

filters

特性:可以挂载在Vue实例里面,但不依赖与Vue实例,也可以接受临时变量,可接受参数。无缓存机制。只读不写。只作为一个值的特殊处理方法

适用场景:对一个值进行修饰后显示,比如根据时间戳返回年月日,根据时间戳返回剩余天数,根据返回的数值格式化显示金额

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

The issue contains a Chinese comparison of Vue computed properties, watchers, and filters, but names no file, test, or documentation entry point. First locate the repository's documentation structure and decide where this explanation belongs; done means the distinctions and use cases are documented clearly and accurately.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
documentation
Issue type
Documentation
Difficulty
1/5
Estimated time
Under an hour
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.