element-plus [Component] [upload] upload组件上传时data对象中传递数组会报错

qoefvg9y  于 2个月前  发布在  其他
关注(0)|答案(2)|浏览(30)

Bug Type: Component

Environment

  • Vue Version: 3.3.4
  • Element Plus Version: 2.3.12
  • Browser / OS: Windows Chrome 116.0.5845.141
  • Build Tool: Vite

Reproduction

  • el-upload

Element Plus Playground

Steps to reproduce

<script lang="ts" setup>
const data = { a: 1, list: [1, 2, 3] }
</script>

<template>
  <el-upload class="upload-demo" action="https://run.mocky.io/v3/9d059bf9-4660-45f2-925d-ce80ad6c4d15" :data="data">
    <el-button type="primary">Click to upload</el-button>
    <template #tip>
      <div class="el-upload__tip">
        jpg/png files with a size less than 500KB.
      </div>
    </template>
  </el-upload>
</template>

What is Expected?

upload的组件参数data对象中携带数组不报错

What is actually happening?

Uncaught (in promise): Failed to execute 'append' on 'FormData': parameter 2 is not of type 'Blob'.

Additional comments

if (option.data) {
    for (const [key, value] of Object.entries(option.data)) {
      if (isArray(value) && value.length) formData.append(key, ...value)
      else formData.append(key, value)
    }
  }

是不是ajax.ts文件中 ajaxUpload方法中这段代码的实现有问题

hs1ihplo

hs1ihplo1#

formData.append(key, ...value)

这里的值有问题,短期可以将数组 JSON.stringify() 下

ki0zmccv

ki0zmccv2#

@boomboy4 对 我看element-ui传递对时候是转换成1,2,3的形式

相关问题