Skip to content

Upload ​

Brief Introduction ​

The Upload component is used for file upload functionality, supporting both regular file upload and avatar upload modes. mengyue-components has encapsulated it and performed vitest testing. You can use <MYUpload></MYUpload> or <MYUpload /> to implement file upload functionality.

Basic Usage ​

Basic File Upload ​

Basic file upload functionality supporting single or multiple file selection.

Code Demo
展开代码

Avatar Upload ​

Use the avatar prop to enable avatar upload mode.

Code Demo
👤 Click to upload avatar
Current avatar: Not set
展开代码

File Type Restriction ​

Use the accept prop to restrict the file types that can be uploaded.

Code Demo
展开代码

Custom Request Headers ​

Use the headers prop to set custom headers for the upload request.

Code Demo
展开代码

Hide File List ​

Use the show-file-list prop to control whether the file list is displayed.

Code Demo
展开代码

API Reference ​

Props ​

PropDescriptionTypeOptionsDefault
actionUpload URLstring—Required
headersRequest headers for uploadobject—{}
acceptAccepted file typesstring—''
multipleWhether to support multiple file selectionboolean—false
avatarWhether in avatar upload modeboolean—false
srcAvatar URLstring—''
show-file-listWhether to show uploaded file listboolean—true
onSuccessCallback function on successful uploadfunction—undefined
onErrorCallback function on failed uploadfunction—undefined
onProgressCallback function on upload progressfunction—undefined

Events ​

Event NameDescriptionParameters
successTriggered when file upload is successfulres: any, file: File
errorTriggered when file upload failserr: any, file: File
progressTriggered on upload progress changepercent: number, file: File

Slots ​

Slot NameDescription
defaultText content of the upload button
iconIcon of the upload button

Type Definitions ​

typescript
interface UploadProps {
  action: string;
  headers?: Record<string, string>;
  accept?: string;
  multiple?: boolean;
  avatar?: boolean;
  src?: string;
  showFileList?: boolean;
  onSuccess?: (res: any, file: File) => void;
  onError?: (err: any, file: File) => void;
  onProgress?: (percent: number, file: File) => void;
}

Released under the MIT License.