【发布时间】:2020-11-26 04:19:13
【问题描述】:
我正在从 REST API 获取 JSON 数据(订单)并使用 Vue js 在动态 HTML 表中显示。表格中的每一行都有一个“打印”按钮。按钮的目的是打印结构中的行数据,基本上是一张账单。 为此,我想突出显示新添加的行,直到用户单击“打印”按钮。我如何实现这一目标? 我每分钟都在刷新桌子。 这是我的代码。
<tr v-for="orders, index in orders">
<th scope="row">{{ index + 1 }}</th>
<td>{{ orders.id }}</td>
<td>{{ orders.billing.first_name + " " +orders.billing.last_name }}</td>
<td>{{ orders.date_created }}</td>
<td>{{ orders.billing.phone}}</td>
<td>{{ orders.billing.address_1 + ", " + orders.billing.address_2 + ", " + orders.billing.city + orders.billing.postcode }}</td>
<td>{{ orders.line_items.name}}</td>
<td>{{ orders.total}}</td>
<td><button class="btn btn-primary" (click)="printBill(data)">Print</button></td>
</tr>
</tbody>
</table>
</div>
<script>
var app = new Vue({
el: '#app',
data: {
orders: []
},
mounted: function() {
axios.get('https://localhost/Site/wp-json/wc/v3/orders?consumer_key=KEY&consumer_secret=KEY1')
.then(response => {
this.orders = response.data;
console.log(response);
})
.catch(error => {
console.log(error);
});
},
})
</script>
【问题讨论】:
-
每一行的数据模型都应该包含一个标志,表明它是新的还是已经打印出来,然后使用它来将样式绑定到该行。当您打印该行时,请关闭该标志。
-
感谢您的回答。我是网络开发的新手。我可以知道你所说的标志和绑定是什么意思吗?
标签: javascript html jquery vue.js