如何从数组中删除项目?

时间:2020-04-05 10:26:42

标签: javascript laravel vue.js laravel-blade

我有这个

<span @click="remove(product)" class="btn btn-sm btn-danger"><i class="fa fa-times"></i></span> element, It triggers this function:<br/>

remove(product) {
  this.form.products.$remove(product);
} <br/>

但是它输出以下错误:TypeError: this.form.products.$remove is not a function我不知道出了什么问题。

1 个答案:

答案 0 :(得分:1)

使用view_namespace '=>' vendor.template.admin ', \ Resources \ views \ vendor \ template \ admin \ 方法从数组中删除项目

首先获取商品的索引

splice

然后使用let index = this.form.products.indexOf(product);

将其删除
splice