我有一個購物車/訂單列表,我將其綁定到一個工作正常的數(shù)組。我最近為添加到數(shù)組中的每個項目添加了一個行號,還有一個按鈕行。問題是我將它們綁定到當前行,如下所示<div id="table"> <table class="table table-sm table-bordered table-striped"> <thead class="thead-dark"> <tr> <th scope="col">#</th> <th scope="col">Product</th> <th scope="col">Type</th> <th scope="col">Attribute</th> <th scope="col">Height</th> <th scope="col">Width</th> <th scope="col">Price</th> <th width="1%" scope="col">Remove</th> </tr> </thead> <tbody> <tr v-for="(item, index) in table_products"> <td>{{ index +1 }}</td> <td>{{ item.product }}</td> <td>{{ item.type }}</td> <td>{{ item.attribute }}</td> <td>{{ item.height }}</td> <td>{{ item.width }}</td> <td>{{ item.price }}</td> <td><button class="btn btn-danger" @click="deleteRow(index)">X</button></td> </tr> </tbody> </table> </div> </div>我從來沒有遇到過問題,因為綁定項值為空,因此從未創(chuàng)建該行。但現(xiàn)在索引和按鈕創(chuàng)建表的第一行。有沒有辦法可以在頁面加載時清除數(shù)組,或者我是否以錯誤的方式進行操作?
具有 Vue(2) 綁定的 HTML 表格行
呼喚遠方
2023-08-18 13:53:01