vuetify-avatar-uploader
🐨
v-avatar
+ file uploads
Wraps Vuetify's v-avatar
component with file upload magic.
- User clicks on their avatar
- User selects an image file to use as their new avatar
- File is uploaded to your API
- User's avatar is replaced ✨
Installation
npm i vuetify-avatar-uploader
Module
components: VAvatarUploader
Browser
Usage
At a minimum, you must provide :url
and :request
properties:
Example
The following is a real-world example of how the library can be used to support user avatar uploads:
API
Props
Name | Description | Type | Required | Default |
---|---|---|---|---|
url |
URL of the avatar | String |
Yes | |
request |
Performs the file upload | Function |
Yes | |
rename |
Renames the file before upload | Function |
No | file => file.name |
field |
FormData field name to use for file data |
String |
No | 'file' |
clickable |
Determines if the user can click to upload | Boolean |
No | true |
maxSize |
Maximum file upload size (in KiB) | Number |
No | 2048 |
headers |
Optional HTTP headers to send with upload request | Object |
No | {} |
avatar |
Core v-avatar configuration object |
Object |
No | {} |
Events
Name | Description |
---|---|
success |
File upload succeeded |
progress |
File upload progress (axios only) |
cancel |
File upload interrupted (i.e. user clicked on avatar while uploading) |
replace |
User clicks on a pre-existing avatar (overrides default file selection flow!) |
failed |
File upload failed |
error-type |
File upload MIME type is unsupported |
error-size |
File upload exceeds maximum size |
error-empty |
File upload is empty |
Slots
Name | Description |
---|---|
none |
Displayed when the url prop is falsy |
loading |
Displayed when an avatar is being uploaded |
Future
- Document more real-world examples
- Provide configuration options for
v-progress-bar
- Support upload cancellations
- Allow custom supported MIME types
- Allow custom form property name for file uploads
- Emit event on empty files
License
MIT