Never use V-IF and V-for on the same element at the same time.
<!-- bad: control error-->
<ul>
<li
v-for="user in users"
v-if="shouldShowUsers"
:key="user.id">
{{ user.name }}
</li>
</ul>
We tend to do this in two common situations:
To filter items in a list (such as V-for = “user in users” V-IF = “user.Isactive”). In this case, replace users with a calculated attribute (such as activeusers) to return the filtered list.
computed: {
activeUsers: function () {
return this.users.filter((user) => {
return user.isActive
})
}
}
<ul>
<li
v-for="user in activeUsers"
:key="user.id">
{{ user.name }}
</li>
</ul>
To avoid rendering lists that should have been hidden (such as V-for = “user in users” V-IF = “shouldshowusers”). In this case, move the V-IF to the container element (such as UL, OL).
<!-- bad -->
<ul>
<li
v-for="user in users"
v-if="shouldShowUsers"
:key="user.id">
{{ user.name }}
</li>
</ul>
<!-- good -->
<ul v-if="shouldShowUsers">
<li
v-for="user in users"
:key="user.id">
{{ user.name }}
</li>
</ul>
Similar Posts:
- Four ways to solve selenium’s error “element is not clickable at point…”
- How to Solve Tensorflow SincNet Error
- Fast locating nonetype ‘object is not Iterable in Python
- Qiankun Error: Target container with #container not existed while xxx mounting!
- Python,NameError: name ‘math’ is not defined
- ImportError: cannot import name ‘patterns’
- How to Solve Error: Cannot read property ‘map’ of undefined
- How to Solve Python TypeError: ‘list’ object is not callable
- Component is missing template or render function [How to Solve]