为了账号安全,请及时绑定邮箱和手机立即绑定

如何从数组中删除一个项目?

如何从数组中删除一个项目?

月关宝盒 2022-06-16 09:50:03
我有这个<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 回答

?
汪汪一只猫

TA贡献1898条经验 获得超8个赞

使用该splice方法从数组中删除项目

首先获取item的索引

let index = this.form.products.indexOf(product);

然后使用删除它splice

this.form.products.splice(index,1);


查看完整回答
反对 回复 2022-06-16
  • 1 回答
  • 0 关注
  • 137 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号