码迷,mamicode.com
首页 > 其他好文 > 详细

vue中的列表项删除操作

时间:2018-04-03 17:36:58      阅读:174      评论:0      收藏:0      [点我收藏+]

标签:for   script   method   index   rip   pre   删除   vue   gpo   

<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>

 

vue中的列表项删除操作

标签:for   script   method   index   rip   pre   删除   vue   gpo   

原文地址:https://www.cnblogs.com/xuxiaoxia/p/8708904.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!