vue中的列表項刪除操作


<script> Vue({ data: { orders: [] }, created() { $.get( { url: 'orders', dataType: 'json' }) .then( data => { this.orders = data; }); }, methods: { delete(index) { // 用索引刪除 this.orders.splice(index, 1); }, deleteByID(id) { this.orders.splice(this.orders.find( order => { return order.id === id; }), 1); } } }); </script> <tr v-for="(order, index) in orders"> <td>...</td> <td> <button type="button" @click="delete(index)">用索引刪除</button> <button type="button" @click="deleteByID(order.id)">用 ID 刪除</button> </td> </tr>

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM