CUI/SolidJs
预览
  • CUI-Admin
    权限管理开发平台

Upload 上传

代码演示

customRequest

通过 customRequest 属性可以自定义上传行为

tsx
customRequest = ({file, onProgress, onSuccess, onError}) => {
    // file: File 上传的文件对象
    // onProgress: Function 上传进度回调
    // onSuccess: Function 上传成功回调
    // onError: Function 上传失败回调
}

属性

属性说明类型默认值
classList自定义classObject-
class自定义classstring-
style自定义样式Object
action上传的地址string
namename属性string
multiple是否支持多选文件boolean
webkitdirectory是否开启选择文件夹,部分浏览器适用boolean
accept接受上传的文件类型string
beforeUpload上传文件之前的钩子,参数为上传的文件,若返回 false 或者 Promise 则停止上传Function
format支持的文件类型,与 accept 不同的是,format 是识别文件的后缀名string[]
maxSize文件大小限制,单位bNumber
headers设置上传的请求头部Object
withCredentials支持发送 cookie 凭证信息boolean
data上传时附带的额外参数Object
defaultFileList默认已上传的文件列表Array
type上传控件的类型select | dragselect
paste是否支持粘贴上传文件boolean
ref组件引用any
getFileUrl自定义预览的url地址Function
listType列表的类型 pictureboolean
customRequest自定义上传行为({file, onProgress, onSuccess, onError}) => void
onProgress文件上传时的钩子,返回字段为 event, file, fileListFunction
onSuccess文件上传成功时的钩子,返回字段为 response, file, fileListFunction
onError文件上传失败时的钩子,返回字段为 error, file, fileListFunction
onRemove文件列表移除文件时的钩子,返回字段为 file, fileListFunction
onPreview点击已上传的文件链接时的钩子,返回字段为 可以通过 file.response 拿到服务端返回数据Function
onFormatError文件格式验证失败时的钩子,返回字段为 file, fileListFunction
onExceededSize文件超出指定大小限制时的钩子,返回字段为 file, fileListFunction

事件

事件名称说明返回值
onProgress文件上传时的钩子event, file, fileList
onSuccess文件上传成功时的钩子response, file, fileList
onError文件上传失败时的钩子error, file, fileList
onRemove文件列表移除文件时的钩子file, fileList
onPreview点击已上传的文件链接时的钩子file
onFormatError文件格式验证失败时的钩子file, fileList
onExceededSize文件超出指定大小限制时的钩子file, fileList