Vue 批量删除按钮操作报错:voucherGroupId 和 voucherIdList 未追加到 formData

/** 批量删除按钮操作 */
handleDelete(row) {
  console.log(row, 'row');
  this.$confirm(
    '是否确认删除凭证组编号为' + row.voucherId + '的数据项?',
    '警告',
    {
      confirmButtonText: '确定',
      cancelButtonText: '取消',
      type: 'warning',
    }
  )
    .then(() => {
      let voucherId = this.selectedRows.map((row) => row.voucherId);
      console.log('voucherIdList', voucherId);
      console.log(' this.voucherGroupId', this.voucherGroupId);
      if (!this.voucherGroupId && !this.voucherId) {
        return;
      }
      let formData = new FormData();
      // formData.append('voucherGroupId', this.voucherGroupId);
      // formData.append('voucherIdList', voucherId);
      formData.append('voucherGroupId', this.voucherGroupId);
      voucherId.forEach((voucherId) => {
        formData.append('voucherIdList[]', voucherId);
      });
      console.log(' formdata', formData);
      return delVoucherGroupRelList(formData);
    })
    .then(() => {
      this.getVoucher();
      this.msgSuccess('删除成功');
    })
    .catch(() => {});
},
<el-button @click='handleDelete(row)'>删除</el-button>

为什么报错 明明拿到了 voucherIdList this.voucherGroupId 但是为什么没有追加到 formdata 里面

根据提供的代码,可能有以下几个可能的原因导致voucherGroupIdvoucherIdList没有追加到formData中:

  1. this.voucherGroupIdvoucherId的值可能为空或未定义。确保这两个值都有正确的值。

  2. map函数的使用可能不正确。请确保this.selectedRows是一个数组,并且row.voucherId是其中每个元素的属性。

  3. voucherId.forEach循环中,你使用了与外部循环相同的变量名voucherId。这可能导致变量名称的冲突和错误的值。尝试使用不同的变量名,例如id

请检查这些问题并确保它们正确。如果问题仍然存在,请提供更多的代码和错误信息以便更好地理解问题。


原文地址: https://www.cveoy.top/t/topic/m3kQ 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录