vuejs / vuejs/docs

Documentation improvement for computed property

Open
#2,150 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Vue
Stars
3.2k
Forks
5k
Avg merge
14d 17h
Merged PRs (30d)
1

Description

It would be helpful if in the computed documentation for vue 2 and 3 that:

In a computed property, if you try to access a property on the instance in a branch that doesn’t run, then Vue won’t know about that dependency and won’t re-run when that dependency is assigned a new value. Link to original quote

Initial discussion

Example

When the IF test is TRUE, if the variables contained inside the ELSE statement and their values change, the computed is not triggered. E.g. computedInSomeCases

One way to prevent this, in case you want the computed to run always, is to use the variables outside the IF statement, like in computedAlways

computed: {
        computedInSomeCases() {
          return this.a ? this.b : this.c;
        },

        computedAlways() {
          const b_copy = this.b;
          const c_copy = this.c;
          return this.a ? b_copy : c_copy;
        },
},

data() {
   return {
     a: true,
     b: 1,
     c: 2
   };
}

Fiddle to test

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

Start with the computed-property documentation for Vue 2 and Vue 3, using the quoted forum explanation and the provided example as the requirements. Review how conditional dependencies are currently described, then update the relevant documentation so the behavior and the shown workaround are clear; the work is done when both versions accurately explain the example.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
documentation
Issue type
Documentation
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.