我尝试了How should customRequest be set in the Ant Design Upload component to work with an XMLHttpRequest?,但不适用于ant design vue。有人可以写一个例子吗?

最佳答案

这是HTML组件:

<a-upload-dragger
    name="file"
    :multiple="true"
    :customRequest="uploadfiles"
    @change="handleChange">
</a-upload-dragger>


您需要处理customRequest:

  uploadfiles({ onSuccess, onError, file }) {
    this.upload(file)
      .then(() => {
        onSuccess(null, file);
      })
      .catch(() => {
        console.log('error');
      });
  };


文件具有这样的结构:

name: "YourFileName.txt"
lastModified: ...
lastModifiedDate: ...
webkitRelativePath: ""
size: 24
type: "text/plain"
uid: "vc-upload-xxxxxx..."


您可以实现自己的上传功能。

您可以处理文件上传进度的状态更改:

handleChange(info) {
    const status = info.file.status;
    if (status !== 'uploading') {
      // show update progress console.log(info.file, info.fileList);
    }
    if (status === 'done') {
      // show success message
    } else if (status === 'error') {
      // show error message
    }
}

关于javascript - 如何为Ant设计Vue编写customRequest for Upload组件,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/59816834/

10-12 04:07