Customize upload button type and text using slot. Set limit and on-exceed to limit the maximum number of uploads allowed and specify method when the limit is exceeded. Plus, you can abort removing a file in the before-remove hook.
export function UploadFileList() { const [fileList, setFileList] = useState<UploadUserFile[]>(PICTURE_FILES); const handleChange: UploadProps["onChange"] = () => { setFileList((prev) => prev.slice(-3)); }; return ( <ElUpload fileList={fileList} onFileListChange={setFileList} action={ACTION} onChange={handleChange} tip={ <div className="el-upload__tip"> jpg/png files with a size less than 500kb </div> } > <ElButton type="primary">Click to upload</ElButton> </ElUpload> );}
Drag to Upload
You can drag your file to a certain area to upload it.
Drop file here or click to upload
jpg/png files with a size less than 500kb
export function UploadDragAndDrop() { return ( <ElUpload action={ACTION} drag multiple tip={ <div className="el-upload__tip"> jpg/png files with a size less than 500kb </div> } > <ElIcon className="el-icon--upload"> <UploadFilled /> </ElIcon> <div className="el-upload__text"> Drop file here or <em>click to upload</em> </div> </ElUpload> );}
Upload Directory 2.13.1
Enable folder upload via the directory prop.
After enabling it, only folders can be selected, and after selecting a folder, the files within the folder will be flattened.
Drop directory here or click to upload
export function UploadDirectory() { const handleChange = (uploadFile: UploadFile, uploadFiles: UploadFile[]) => { console.log(uploadFile, uploadFiles); }; return ( <ElUpload action={ACTION} drag directory multiple onChange={handleChange} > <ElIcon className="el-icon--upload"> <UploadFilled /> </ElIcon> <div className="el-upload__text"> Drop directory here or <em>click to upload</em> </div> </ElUpload> );}
Manual Upload
jpg/png files with a size less than 500kb
export function UploadManual() { const uploadRef = useRef<UploadExpose>(null); const submitUpload = () => { uploadRef.current?.submit(); }; return ( <ElUpload ref={uploadRef} action={ACTION} autoUpload={false} trigger={<ElButton type="primary">select file</ElButton>} tip={ <div className="el-upload__tip"> jpg/png files with a size less than 500kb </div> } > <ElButton type="success" style={gapLeftStyle} onClick={submitUpload}> upload to server </ElButton> </ElUpload> );}
API
Attributes
Name
Description
Type
Default
action required
request URL.
string
#
headers
request headers.
object
—
method
set upload request method.
string
post
multiple
whether uploading multiple files is permitted.
boolean
false
data
additions options of request. support Awaitable data and Function since v2.3.13.
object / Function
{}
name
key name for uploaded file.
string
file
with-credentials
whether cookies are sent.
boolean
false
show-file-list
whether to show the uploaded file list.
boolean
true
drag
whether to activate drag and drop mode.
boolean
false
accept
accepted file types, will not work when thumbnail-mode === true.
hook function when select file or upload file success or upload file fail.
Function
—
on-exceed
hook function when limit is exceeded.
Function
—
before-upload
hook function before uploading with the file to be uploaded as its parameter. If false is returned or a Promise is returned and then is rejected, uploading will be aborted.
Function
—
before-remove
hook function before removing a file with the file and file list as its parameters. If false is returned or a Promise is returned and then is rejected, removing will be aborted.
Function
—
file-list / v-model:file-list
default uploaded files.
array
[]
list-type
type of file list.
enum
text
auto-upload
whether to auto upload file.
boolean
true
http-request
override default xhr behavior, allowing you to implement your own upload-file's request.
whether to support uploading directory. After enabling it, only folders can be selected, and after selecting a folder, the files within the folder will be flattened.
boolean
false
Slots
Name
Description
Type
default
customize default content.
-
trigger
content which triggers file dialog.
-
tip
content of tips.
-
file
content of thumbnail template.
object
Exposes
Name
Description
Type
abort
cancel upload request. When a file is specified, abort the corresponding pending upload; when no file is specified, abort all pending uploads.
Function
submit
upload the file list manually.
Function
clearFiles
clear the file list (this method is not supported in the before-upload hook).
Function
handleStart
select the file manually.
Function
handleRemove
remove the file manually. file and rawFile has been merged. rawFile will be removed in v2.2.0.