【发布时间】:2020-11-29 09:40:13
【问题描述】:
我正在使用 axios 从 Vue 中的外部 Api 获取数据(订单)。我获得了 JSON 数据,并且能够在 HTML 表格中显示它。现在我正在尝试过滤数据以仅显示要使用的相关数据。在我的 Json 数据中,我有一个名为“订单状态:已完成/处理中”的字段。现在我只想显示状态为“处理中”的 json 数据以实现我的目标。
我正在尝试将 v-if 与 v-for 一起使用,但我无法获取某些订单数据和视图。
表格设置为每分钟更新一次。
这是我的代码:
html代码
**<div class ="container mt-4" id="app">
<table class="table table-bordered">
<thead>
<tr>
<th scope="col">Order id</th>
<th scope="col">Name</th>
<th scope="col">Order Date</th>
<th scope="col">Phone</th>
<th scope="col">Address</th>
<th scope="col">Items</th>
<th scope="col">Total</th>
<th scope="col">Print</th>
</tr>
</thead>
<tbody>
<tr
v-for="(order, index) in orders" v-if="order.status === "processing""
:key="order.id"
:class="{highlight: !order.is_printed}"
>
<td>{{ order.id }}</td>
<td>{{ order.billing.first_name + " " +order.billing.last_name }}</td>
<td>{{ order.date_created }}</td>
<td>{{ order.billing.phone}}</td>
<td>{{ order.billing.address_1 + ", " + order.billing.address_2 + ", " + order.billing.city + order.billing.postcode }}</td>
<td>{{ order.line_items[0].name}} </td>
<td>{{ order.total}}</td>
<td><button class="btn btn-primary" @click="printBill(order)">Print</button>
</tr>
</tbody>
</table>**
Vue
<script>
var app = new Vue({
el: '#app',
data: {
orders: []
},
mounted: function() {
// API Call function to be implemented here....
</script>
【问题讨论】:
标签: javascript html jquery api vue.js