跳转到内容

上传 Upload

点击上传用户头像,可使用 beforeUpload 限制用户上传的图片格式和大小。

上传组件的基本用法。

on-before-remove 会在每一个文件移除之前执行。如果返回 false 或者 Promise.reject, 那么将会取消当前文件的操作。

beforeUpload 会在每一个文件上传之前执行。如果返回 false 或者 Promise.reject, 那么将会取消当前文件的上传。

可以通过插槽 upload-button 传入自定义内容作为文件上传的触发节点。

自定义图标

可以通过 directory 开启文件夹上传

通过设置 draggable 开启对拖拽的支持。

通过 limit 限制上传的最大数量。超出后上传按钮会隐藏.

通过设置 list-type="picture-card" 开启照片墙模式。

通过设置 list-type="picture" 开启图片列表样式

可以通过 custom-request 实现自定义上传请求。

设置 auto-uploadfalse 时候,可以通过调用 submit 方法进行手动上传。

可以指定默认的已上传文件列表。

参数名描述类型默认值版本
file-list (v-model)文件列表FileItem[]-
default-file-list默认的文件列表(非受控状态)FileItem[][]
accept接收的上传文件类型,具体参考 HTML标准string-
action上传的URLstring-
disabled是否禁用booleanfalse
multiple是否支持多文件上传booleanfalse
directory是否支持文件夹上传(需要浏览器支持)booleanfalse
draggable是否支持拖拽上传booleanfalse
tip提示文字string-
headers上传请求附加的头信息Record<string, string>-
data上传请求附加的数据Record<string, string | Blob>| ((fileItem: FileItem) => Record<string, string | Blob>)-
name上传的文件名string | ((fileItem: FileItem) => string)-
with-credentials上传请求是否携带 cookiebooleanfalse
custom-request自定义上传行为(option: RequestOption) => UploadRequest-
limit限制上传文件的数量。0表示不限制number0
auto-upload是否自动上传文件booleantrue
show-file-list是否显示文件列表booleantrue
show-remove-button是否显示删除按钮booleantrue2.11.0
show-retry-button是否显示重试按钮booleantrue2.11.0
show-cancel-button是否显示取消按钮booleantrue2.11.0
show-upload-button是否显示上传按钮。2.14.0 版本新增 showOnExceedLimit 支持boolean | { showOnExceedLimit: boolean }true2.11.0
show-preview-button照片墙是否显示预览按钮booleantrue2.42.0
download是否在 <a> 链接上添加 download 属性booleanfalse2.11.0
show-link在列表模式下,如果上传的文件存在 URL 则展示链接。如果关闭仅展示文字并且点击可以触发 preview 事件。booleantrue2.13.0
image-loading__SD_PLACEHOLDER_0__ 的原生 HTML 属性,需要浏览器支持'eager' | 'lazy'-2.11.0
list-type图片列表类型'text' | 'picture' | 'picture-card''text'
response-url-keyResponse中获取图片URL的key,开启后会用上传的图片替换预加载的图片string | ((fileItem: FileItem) => string)-
custom-icon自定义图标CustomIcon-
image-preview是否使用 ImagePreview 组件进行预览booleanfalse2.14.0
on-before-upload上传文件前触发(file: File) => boolean | Promise<boolean | File>-
on-before-remove移除文件前触发(fileItem: FileItem) => Promise<boolean>-
on-button-click点击上传按钮触发(如果返回 Promise 则会关闭默认 input 上传)(event: Event) => Promise<FileList> | void-
事件名描述参数
exceed-limit上传的文件超出限制后触发fileList: FileItem[]
files: File[]
change上传的文件状态发生改变时触发fileList: FileItem[]
fileItem: fileItem
progress上传中的文件进度改变时触发fileItem: fileItem
ev: ProgressEvent
preview点击图片预览时的触发fileItem: FileItem
success上传成功时触发fileItem: FileItem
error上传失败时触发fileItem: FileItem
方法名描述参数返回值版本
submit上传文件(已经初始化完成的文件)fileItem: FileItem-
abort中止上传fileItem: FileItem-
updateFile更新文件id: string
file: File
-
upload上传文件files: File[]-2.41.0
插槽名描述参数版本
extra-button上传列表额外按钮fileItem: FileItem2.43.0
image自定义图片fileItem: FileItem2.23.0
file-name文件名称-2.23.0
file-icon文件图标-2.23.0
remove-icon删除图标-2.23.0
preview-icon预览图标-2.23.0
cancel-icon取消图标-2.23.0
start-icon开始图标-2.23.0
error-icon失败图标-2.23.0
success-icon成功图标-2.23.0
retry-icon重试图标-2.23.0
upload-button上传按钮-
upload-item上传列表的项目fileItem: FileItem
index: number
参数名描述类型默认值
uid当前上传文件的唯一标示string-
status当前上传文件的状态FileStatus-
file文件对象File-
percent上传进度百分比number-
response当前文件上传请求返回的响应any-
url文件地址string-
name文件名string-
参数名描述类型默认值
startIcon开始图标RenderFunction-
cancelIcon取消图标RenderFunction-
retryIcon重试图标RenderFunction-
successIcon成功图标RenderFunction-
errorIcon失败图标RenderFunction-
removeIcon移除图标RenderFunction-
previewIcon预览图标RenderFunction-
fileIcon文件图标(fileItem: FileItem) => VNode-
fileName文件名(fileItem: FileItem) => string | VNode-
参数名描述类型默认值
action上传的URLstring-
headers请求报文的头信息Record<string, string>-
name上传文件的文件名string | ((fileItem: FileItem) => string)-
fileItem上传文件FileItem-
data附加的请求信息Record<string, string | Blob> | ((fileItem: FileItem) => Record<string, string | Blob>)-
withCredentials是否携带cookie信息booleanfalse
onProgress更新当前文件的上传进度。percent: 当前上传进度百分比(percent: number, event?: ProgressEvent) => void-
onSuccess上传成功后,调用onSuccess方法,传入的response参数将会附加到当前上传文件的response字段上(response?: any) => void-
onError上传失败后,调用onError方法,传入的response参数将会附加到当前上传文件的response字段上(response?: any) => void-
参数名描述类型默认值
abort终止上传() => void-