From e13b49eeb20bcf2fd6652f8ea8340eab45b4382c Mon Sep 17 00:00:00 2001 From: NataliaTepluhina Date: Wed, 23 Sep 2020 20:36:52 +0300 Subject: [PATCH 01/12] fix: fixed v-if v-for on styleguide --- src/style-guide/README.md | 79 +++++++++------------------------------ 1 file changed, 17 insertions(+), 62 deletions(-) diff --git a/src/style-guide/README.md b/src/style-guide/README.md index 3c1280838f..1c99304e1a 100644 --- a/src/style-guide/README.md +++ b/src/style-guide/README.md @@ -196,7 +196,7 @@ There are two common cases where this can be tempting: - To avoid rendering a list if it should be hidden (e.g. `v-for="user in users" v-if="shouldShowUsers"`). In these cases, move the `v-if` to a container element (e.g. `ul`, `ol`). ::: details Detailed Explanation -When Vue processes directives, `v-for` has a higher priority than `v-if`, so that this template: +When Vue processes directives, `v-if` has a higher priority than `v-for`, so that this template: ``` html ``` -Will be evaluated similar to: +Will throw an error, because `v-if` directive will be evaluated first and property `user` does not exist at this moment. -``` js -this.users.map(user => { - if (user.isActive) { - return user.name - } -}) -``` - -So even if we only render elements for a small fraction of users, we have to iterate over the entire list every time we re-render, whether or not the set of active users has changed. - -By iterating over a computed property instead, like this: +This could be fixed by iterating over a computed property instead, like this: ``` js computed: { @@ -243,40 +233,18 @@ computed: { ``` -We get the following benefits: +Alternatively, we can use a `