【发布时间】:2022-01-25 15:58:36
【问题描述】:
我是 vue.js 的新手,我正在尝试在表格内的每一行中添加垃圾图标和 激活它以删除行但它不起作用 ,以及如何将一个单元格的输入作为下拉菜单或表格行内的列表。 下面的脚本是从教程https://smarttutorials.net/dynamically-add-or-remove-table-row-using-vuejs/复制而来的 非常感谢您的帮助
<!DOCTYPE html>
<html>
<head>
<title>Report Generation</title>
<meta charset = "UTF-8" />
</head>
<body>
<div id="app">
<table>
<thead>
<tr>
<th scope ="col">#</th>
<th scope ="col">Item No</th>
<th scope ="col text-right">Item Name</th>
<th scope ="col text-right">Price</th>
<th scope ="col text-right">Quntatiy</th>
<th scope ="col text-right">Total</th>
</tr>
</thead>
<tr v-for="(invoice_product, index) in invoice_products" :key="index">
<td scope="row" class="trashIconContainer">
<i class="far fa-trash-alt" @click="deleteRow(index, invoice_product)"></i>
</td>
<td>
<input class="form-control" type="text" v-model="invoice_product.product_no" />
</td>
<td>
<input class="form-control" type="text" v-model= "invoice_product.product_no" />
</v-col>
</td>
<td>
<input class="form-control text-right" type="number" min="0" step=".01" v-model="invoice_product.product_price" @change="calculateLineTotal(invoice_product)"
/>
</td>
<td>
<input class="form-control text-right" type="number" min="0" step=".01" v-model="invoice_product.product_qty" @change="calculateLineTotal(invoice_product)"
/>
</td>
<td>
<input readonly class="form-control text-right" type="number" min="0" step=".01" v-model="invoice_product.line_total" />
</td>
</tr>
</table>
<button type='button' class="btn btn-info" @click="addNewRow">
<i class="fas fa-plus-circle"></i>
Add
</button>
<button @click="deleteRow">
<i class="fas fa-plus-circle"></i>
Delete
</button>
</template>
</div>
<script src= "js/vue.js"> </script>
<script>
var app = new Vue({
el: "#app",
data: {
invoice_products: [{
product_no: '',
product_name: '',
product_price: '',
product_qty: '',
line_total: 0
}]
},methods: {
deleteRow(index, invoice_product) {
var idx = this.invoice_products.indexOf(invoice_product);
console.log(idx, index);
this.invoice_products.splice(idx, 2);
},
addNewRow() {
this.invoice_products.push({
product_no: '',
product_name: '',
product_price: '',
product_qty: '',
line_total: 0
});
}
}
});
</script>
</body>
</html> ```
【问题讨论】:
-
要使用很棒的字体,您必须包含库或使用 cdn
标签: javascript vue.js vue-tables-2 vuetify-datatable