【问题标题】:Vue if语句同时显示来自api的数据
【发布时间】:2022-01-21 23:27:27
【问题描述】:

我从 Api 获取一些数据,我想检查 vtype 是否为“汽车”。这是我循环的方式:

<tr v-for="vehicles_group in vehicles_groups.data" :key="vehicles_group.gid">
      <td>
           <input type="checkbox">
      </td>
      <!-- <td>{{ vehicles_groups.gid }} </td> -->
      <td>{{ vehicles_group.title }}</td>
      <td>{{ vehicles_group.vtype }}</td>
      <td>{{ vehicles_group.company }}</td>
      <td>{{ vehicles_group.active }}</td>
      <td>{{ vehicles_group.priceincludes }}</td>
      <td>{{ vehicles_group.categories }}</td>
      <td>{{ vehicles_group.earlybook }}</td>
      <td>{{ vehicles_group.earlybook }}</td>
 </tr>

vue 中有没有办法检查 Api 输出的值是否是汽车控制台的东西?

例如

if {{ vehicles_group.vtype }} == car{
   console.log('its a car', vehicles_group.vtype )
}

【问题讨论】:

  • 您的表格已经告诉您这里是否是汽车:{{ vehicle_group.vtype }}

标签: javascript vue.js vuejs2


【解决方案1】:

当然。

如果您想在模板中使用v-if

<td v-if="vehicles_group.vtype == 'car'">
    It's a car
</td>
<td v-else>
    It's not a car
</td>

如果你想在你的组件 JavaScript 代码中这样做,你可以照常进行:

if (vehicles_group.vtype == "car") {
   console.log('its a car', vehicles_group.vtype )
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-15
    • 1970-01-01
    • 2020-02-09
    • 2012-05-06
    相关资源
    最近更新 更多