首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何为Ant design vue编写Upload组件的customRequest

如何为Ant design vue编写Upload组件的customRequest
EN

Stack Overflow用户
提问于 2020-01-20 11:59:32
回答 1查看 1.7K关注 0票数 0

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

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-02-27 17:38:34

这是HTML组件:

代码语言:javascript
复制
<a-upload-dragger
    name="file"
    :multiple="true"
    :customRequest="uploadfiles"
    @change="handleChange">
</a-upload-dragger>

您需要处理customRequest:

代码语言:javascript
复制
  uploadfiles({ onSuccess, onError, file }) {
    this.upload(file)
      .then(() => {
        onSuccess(null, file);
      })
      .catch(() => {
        console.log('error');
      });
  };

文件具有这样的结构:

代码语言:javascript
复制
name: "YourFileName.txt"
lastModified: ...
lastModifiedDate: ...
webkitRelativePath: ""
size: 24
type: "text/plain"
uid: "vc-upload-xxxxxx..."

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

您可以处理文件上传进度的状态变化:

代码语言:javascript
复制
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
    }
}
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/59816834

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档