Skip to content

Upload 上传 ​

基于 Element Plus el-upload 的二次封装,支持多种列表展示模式、文件预览、懒加载预览、删除回调等业务场景。

懒加载预览 ​

上传接口只返回 id,通过 previewUrl 按需获取预览 URL,删除时调用 deleteUrl 删除服务端文件。

支持 .jpg,.png,.gif,.pdf,.doc,.docx,.mp4 格式,最多 10 个文件

modelValueType - 值类型切换 ​

通过 modelValueType 控制 v-model emit 的值类型:array 发送数组(默认),string 发送逗号分隔字符串。

modelValueType="array"(默认)

v-model 绑定为数组,响应式更新

支持 .jpg,.png,.gif,.pdf,.doc,.docx,.mp4 格式,最多 5 个文件
v-model (fileIds): []

modelValueType="string"

v-model 绑定为逗号分隔字符串,适用于后端接口直接接收字符串场景

支持 .jpg,.png,.gif,.pdf,.doc,.docx,.mp4 格式,最多 5 个文件
v-model (fileIdsStr):

API ​

Props ​

参数名说明类型默认值
v-model上传文件后绑定到表单的值string | string[]-
modelValueTypev-model emit 的值类型:array 发送数组,string 发送逗号分隔字符串'string' | 'array''array'
action上传地址string-
accept接受的文件类型string-
limit最大上传数量number-
multiple是否支持多文件boolean-
disabled是否禁用boolean-
listType列表展示类型:text / picture / picture-card / file-previewstring'file-preview'
autoUpload是否自动上传(无 action 时关闭)booleantrue
placeholder上传按钮占位文本string-
responseMapper从服务端响应中提取要存储的值(如 fileId)(response, file) => any-
valueMapper从 file 对象提取值的映射函数(file, response?) => any-
previewUrl根据 fileId 获取文件预览信息的接口(listType=file-preview 时使用)string-
deleteUrl根据 fileId 删除文件的接口(file-preview 模式)string-
showDownload是否显示下载按钮(file-preview 模式)booleantrue
removable是否显示删除按钮(file-preview 模式)boolean-
removeConfirmTitle删除确认框标题(file-preview 模式)string-
removeConfirmMessage删除确认框内容(file-preview 模式)string-
itemWidth卡片宽度(file-preview 模式)string | number-
itemHeight卡片高度(file-preview 模式)string | number-
fileRender自定义文件列表项渲染(file, actions) => VNode-
filePreviewRender自定义文件预览渲染(file, actions) => VNode-
componentProps额外的 el-upload propsRecord<string, any>-

Slots ​

插槽名说明作用域变量
default默认插槽,渲染上传触发器-
file自定义文件列表项(listType 非 file-preview 时生效){ file, remove }
tip提示信息区域-

事件 ​

事件名说明参数
success上传成功时触发(response, file, fileList) => void
update:modelValue文件列表变化时触发(file-preview 模式)(value: string | string[])

Released under the MIT License.