Skip to content

Upload 上传

规则

js
{
    type: "upload",
    field: "pic",
    title: "轮播图",
    value: [
        'http://img1.touxiang.cn/uploads/20131030/30-075657_191.jpg',
        'http://img1.touxiang.cn/uploads/20131030/30-075657_191.jpg'
        ],
    props: {
        action: "/upload.php",
        max: 2,
        onSuccess:function (res, file) {
            file.url = res.url;
        }
    },
}
{
    type: "upload",
    field: "pic",
    title: "轮播图",
    value: [
        'http://img1.touxiang.cn/uploads/20131030/30-075657_191.jpg',
        'http://img1.touxiang.cn/uploads/20131030/30-075657_191.jpg'
        ],
    props: {
        action: "/upload.php",
        max: 2,
        onSuccess:function (res, file) {
            file.url = res.url;
        }
    },
}

参考:naive-ui_Upload

value :Array | String

注意

文件上传成功后需要通过 onSuccess 回调, 将接口返回内容中的 url 赋值给 file.url.否则表单获取不到组件的数据

Props

名称类型默认值说明版本
onSuccessFunctionundefined文件上传成功后回调
abstractbooleanfalse是否不存在 DOM 包裹,不支持 image-card 类型的 Upload
acceptstringundefined接受的文件类型,参考 accept
actionstringundefined请求提交的地址
create-thumbnail-url(file: File) => Promise<string>undefined自定义文件缩略图
custom-request(options: UploadCustomRequestOptions) => voidundefined自定义上传方法,类型参考 UploadCustomRequestOptions
dataObject | ({ file: UploadFileInfo }) => Objectundefined提交表单需要附加的数据
default-file-listArray<UploadFileInfo>[]非受控状态下默认的文件列表
default-uploadbooleantrue选择文件时候是否默认上传
disabledbooleanfalse是否禁用
file-list-styleObjectundefined文件列表区域的样式
file-listArray<UploadFileInfo>undefined文件列表,如果传入组件会处于受控状态
headersObject | ({ file: UploadFileInfo }) => ObjectundefinedHTTP 请求需要附加的 Headers
image-group-propsImageGroupPropsundefinedUpload 中预览图片组件的属性,参考 ImageGroup Props2.24.0
input-propsObjectundefinedfile input 元素的属性2.24.2
list-typestring'text'文件列表的内建样式,textimageimage-card
maxnumberundefined限制上传文件数量
methodstring'POST'HTTP 请求的方法
multiplebooleanfalse是否支持多个文件
namestring'file'文件在提交表单中的字段名
show-cancel-buttonbooleantrue是否显示取消按钮(在 pending、uploading、error 的时候展示),点击取消按钮会触发 on-remove 回调
show-download-buttonbooleanfalse是否显示下载按钮(在 finished 后展示)
show-remove-buttonbooleantrue是否显示删除按钮(在 finished 后时候展示),点击删除按钮会触发 on-remove 回调
show-retry-buttonbooleantrue是否显示重新上传按钮(在 error 时展示)
show-file-listbooleantrue是否显示文件列表
show-preview-buttonbooleantrue是否允许显示预览按钮(在 list-typeimage-card 时生效)
show-triggerbooleantrue是否显示触发元素2.21.5
with-credentialsbooleanfalse是否携带 Cookie
on-change(options: { file: UploadFileInfo, fileList: Array<UploadFileInfo>, event?: Event }) => void | () => {}组件状态变化的回调,组件的任何文件状态变化都会触发回调
on-error(options: { file: UploadFileInfo, event?: ProgressEvent }) => UploadFileInfo | void | undefined文件上传失败的回调2.24.0
on-finish(options: { file: UploadFileInfo, event?: ProgressEvent }) => UploadFileInfo | void | ({ file }) => file文件上传结束的回调,可以修改传入的 UploadFileInfo 或者返回一个新的 UploadFileInfo。注意:file 将会下一次事件循环中被置为 null
on-before-upload(options: { file: UploadFileInfo, fileList: UploadFileInfo[] }) => (Promise<boolean | void> | boolean | void)undefined文件上传之前的回调,返回 falsePromise resolve falsePromise rejected 时会取消本次上传
on-download(file: FileInfo) => voidundefined点击文件下载按钮的回调函数
on-preview(file: FileInfo) => voidundefined点击文件链接或预览按钮的回调函数
on-remove(options: { file: UploadFileInfo, fileList: Array<UploadFileInfo> }) => Promise<boolean> | boolean | any | () => true文件删除回调,返回 falsePromise resolve falsePromise rejected 时会取消本次删除
on-update:file-list(fileList: UploadFileInfo[]) => voidundefined当 file-list 改变时触发的回调函数