掉接口删除数组数据后,不掉查询接口回显数组数据

83 阅读1分钟

使用 splice() 方法从数组中删除指定的元素,在 removeInvoice() 接口调用成功后对 this.faPiaoDataList 数组进行处理,将 item.id 对应的元素从数组中删除。示例代码如下:

removeInvoice(item) {
  this.ids = item.id
  removeInvoice(this.ids).then(res => {
    if (res.code == 200) {
      this.$message.success("删除成功");
      // 将 item.id 对应的元素从 this.faPiaoDataList 数组中删除
      for (let i = 0; i < this.faPiaoDataList.length; i++) {
        if (this.faPiaoDataList[i].id == item.id) {
          this.faPiaoDataList.splice(i, 1);
          break;
        }
      }
    }
  });
},

以上代码中,我们遍历 this.faPiaoDataList 数组,找到 id 属性等于 item.id 的元素,然后使用 splice() 方法从数组中删除该元素。注意,在找到对应元素后需要使用 break; 结束循环,以免多次删除同一个元素。