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",
        limit: 2,
            onSuccess:function (file) {
            file.url = file.response.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",
        limit: 2,
            onSuccess:function (file) {
            file.url = file.response.url;
        }
    },
}

参考:arco-design_Upload

value :Array | String

注意

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

Props

参数名描述类型默认值版本
onSuccess上传成功时触发string-
accept接收的上传文件类型,具体参考 HTML标准string-
action上传的URLstring-
disabled是否禁用booleanfalse
multiple是否支持多文件上传booleanfalse
directory是否支持文件夹上传(需要浏览器支持)booleanfalse
draggable是否支持拖拽上传booleanfalse
tip提示文字string-
headers上传请求附加的头信息object-
data上传请求附加的数据Record<string, unknown>| ((fileItem: FileItem) => Record<string, unknown>)-
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
download是否在 <a> 链接上添加 download 属性booleanfalse2.11.0
show-link在列表模式下,如果上传的文件存在 URL 则展示链接。如果关闭仅展示文字并且点击可以触发 preview 事件。 | booleantrue2.13.0
image-loading<img> 的原生 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) => Promise<boolean>-
on-before-remove移除图片前触发(fileItem: FileItem) => Promise<boolean>-
on-button-click点击上传按钮触发(如果返回 Promise 则会关闭默认 input 上传)(event: Event) => Promise<FileList> | void-

Events

事件名描述参数
exceed-limit上传的图片超出限制后触发fileList: FileItem[] files: File[]
change上传的图片状态发生改变时触发fileList: FileItem[] fileItem: fileItem
progress上传中的图片进度改变时触发fileItem: fileItem event: ProgressEvent
preview点击图片预览时的触发fileItem: FileItem
error上传失败时触发fileItem: FileItem

Released under the MIT License.