D
D
DPS_ninja2020-01-27 15:01:22
Vue.js
DPS_ninja, 2020-01-27 15:01:22

How to do v-if with v-for correctly in vue?

I would like to make a condition, let's say when the name is Tom or Misha, then let's add the number 9 to it. To get a list, but under my condition it was Tom 9, Alex, Vasya, Misha 9. How can this be implemented? also read that v-for cannot be used with v-if
Example:
https://codepen.io/Unknown322/pen/zYOVMPw

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Belyaev, 2020-01-27
@DPS_ninja

also read that v-for cannot be used with v-if
not recommended does not mean it is not recommended, it is recommended to do .filter on the array, and already do v-for on the filtered array and this is due to the fact that vue can cache the filtered array and recalculate cycles only when the array itself changes, but does not respond to changes in elements in German
by subject:
<li v-for="user in users"
    :key="user"
>
    <p>Имя: {{ user }}{{ user === 'Tom' || user === 'Misha' ? ' 9' : '' }}</p>
</li>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question