R
R
r_g_b_a2020-05-19 18:05:10
Vue.js
r_g_b_a, 2020-05-19 18:05:10

How to call a function with parameter passing inside v-if?

Hello.
There is this code:

<li v-for="(todo, index) in todos">
      <div v-if="index === 1">{{ todo.text }}</div>
</li>

Let's say my test condition is much more complicated and larger than comparison with one. Can it somehow be moved to a hotel function? I tried like this, but I get an error.:
<div v-if="isVisible(index)">{{ todo.text }}</div>

computed: {
    isVisible(index) {
      return index === 1;
    }
  }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Aetae, 2020-05-20
@Aetae

Technically , 0xD34F is correct.
Architecturally, in v-for, it is not advisable to use complex calculations, it is correct to make a computed property that returns a prepared and filtered array of the right kind right away.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question