V
V
vetsmen2018-02-21 18:10:59
Vue.js
vetsmen, 2018-02-21 18:10:59

Loop propagation to adjacent Vue.js blocks?

<div v-if="type == 0" v-for="item in items" class="item" key="item">
...
</div>
<div v-else class="cats item" key="cats">
...
</div>

Why do I have blocks with the "cats" key displayed in the cycle that is written in the first block when changing the type? And the fact is that I have access to item from it.
How can I make this "item" loop not refer to "cats"?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
0
0xD34F, 2018-02-21
@vetsmen

Well, obviously v-for has higher precedence, so it's done in both cases.
What to do? Add a v-forwrapper to the element, into which you transfer the v-if.

E
Erbol, 2018-02-21
Kuandykov @Erreke

This is why the style guide recommends avoiding v-if with v-for.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question