E
E
Erl2020-07-21 20:06:29
Vue.js
Erl, 2020-07-21 20:06:29

Why is v-if not working in vue?

Why does it still draw the 2nd template v-else when the condition is triggered? after all, the first condition worked
out, it turns out that if I remove the v-else block, then it works as it should, if it matches, only the necessary lines are shown, but when v-else is added, it draws the entire array

caliber: "12x70"

<template v-for="data in ammo_data">
          <template v-if="data.caliber == caliber">
            <tr v-for="items in data.items" :key="items.id">
              <td data-label="Наименование"><span>{{items.name}}</span></td>
              <td data-label="Калибр"><span>{{items.caliber}}</span></td>
              <td data-label="Урон"><span class="val">{{items.damage}}</span></td>
              <td data-label="Бронепробитие"><span class="val">{{items.arm_pentra}}</span></td>
              <td data-label="Повреждение брони"><span class="val">{{items.arm_damage}}</span></td>
              <td data-label="Вероятность фрагментации"><span class="val">{{items.bullet_frag}}</span></td>
              <td data-label="Скорость (м/сек)"><span class="val">{{items.speed}}</span></td>
              <td data-label="Вероятность рикошет"><span class="val">{{items.ricochet}}</span></td>
            </tr>
          </template>
          <template v-else>
            <tr v-for="items in data.items" :key="items.id" :data-label="data.count">
              <td data-label="Наименование"><span>{{items.name}}</span></td>
              <td data-label="Калибр"><span>{{items.caliber}}</span></td>
              <td data-label="Урон"><span class="val">{{items.damage}}</span></td>
              <td data-label="Бронепробитие"><span class="val">{{items.arm_pentra}}</span></td>
              <td data-label="Повреждение брони"><span class="val">{{items.arm_damage}}</span></td>
              <td data-label="Вероятность фрагментации"><span class="val">{{items.bullet_frag}}</span></td>
              <td data-label="Скорость (м/сек)"><span class="val">{{items.speed}}</span></td>
              <td data-label="Вероятность рикошет"><span class="val">{{items.ricochet}}</span></td>
            </tr>
          </template>
        </template>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Rsa97, 2020-07-21
@NooBiToo

So you have it written:

Если нужный калибр, то отобразить данные
Иначе отобразить данные
That is, the data is displayed anyway.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question