Uploader
Demos
File upload
Set the type
prop to file
to use the file upload mode.
Normal size
- demo-file1.txt
- demo-file2.txt
Small size
- demo-file1.txt
- demo-file2.txt
<template>
<article>
<section>
<h4>Normal size</h4>
<veui-uploader
v-model="files"
action="https://app.fakejson.com/q/ELymQ7xh?token=AWFkjMICPSAB_bO_z-Lnog"
/>
</section>
<section>
<h4>Small size</h4>
<veui-uploader
v-model="files2"
action="https://app.fakejson.com/q/ELymQ7xh?token=AWFkjMICPSAB_bO_z-Lnog"
ui="s"
/>
</section>
</article>
</template>
<script>
import { Uploader } from 'veui'
import { cloneDeep } from 'lodash'
export default {
components: {
'veui-uploader': Uploader
},
data () {
let files = [
{
name: 'demo-file1.txt',
src: '/file/demo-file1.txt',
key: 0
},
{
name: 'demo-file2.txt',
src: '/file/demo-file2.txt',
key: 1
}
]
return {
files,
files2: cloneDeep(files)
}
}
}
</script>
<style lang="less" scoped>
article {
display: flex;
}
section {
width: 45%;
}
</style>
Image upload
Set the type
prop to image
to use the image upload mode.
Normal size
Small size
<template>
<article>
<section>
<h4>Normal size</h4>
<veui-uploader
v-model="images"
type="image"
action="https://app.fakejson.com/q/ELymQ7xh?token=AWFkjMICPSAB_bO_z-Lnog"
>
<template #desc>
Normal size
</template>
</veui-uploader>
</section>
<section>
<h4>Small size</h4>
<veui-uploader
v-model="images2"
type="image"
action="https://app.fakejson.com/q/ELymQ7xh?token=AWFkjMICPSAB_bO_z-Lnog"
ui="s"
>
<template #desc>
Small size
</template>
</veui-uploader>
</section>
</article>
</template>
<script>
import { Uploader } from 'veui'
import { cloneDeep } from 'lodash'
export default {
components: {
'veui-uploader': Uploader
},
data () {
let images = [
{
src: '/images/development/uploader/demo-image1.jpg',
key: 0
},
{
src: '/images/development/uploader/demo-image2.jpg',
key: 1
}
]
return {
images,
images2: cloneDeep(images)
}
}
}
</script>
API
Props
Name | Type | Default | Description | |||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
ui | string= | - | Style variants.
| |||||||||||||||
type | string | 'file' | The type of the uploader.
| |||||||||||||||
value | Object | Array<Object> | - | Returns an array of file objects when The type of single file is | |||||||||||||||
key-field | string | 'key' | Used to specify a unique key for the file object, as a basis for correctly handling the order of the file list when the data changes. | |||||||||||||||
name | string | 'file' | The name of native <input> elements. | |||||||||||||||
action | string | - | Upload URL. | |||||||||||||||
headers | Object | uploader.headers | Extra HTTP headers. Can be globally configured. | |||||||||||||||
with-credentials | boolean | true | The same as the withCredentials option of XMLHttpRequest . | |||||||||||||||
request-mode | string | uploader.requestMode | The request mode of the uploader. Can be globally configured.
| |||||||||||||||
iframe-mode | string | uploader.iframeMode | To specify the callback mode when
| |||||||||||||||
callback-namespace | string | uploader.callbackNamespace | The namespace of the callback function when request-mode is 'iframe' and iframe-mode is 'callback' , will be placed under the window object. Can be globally configured. | |||||||||||||||
data-type | string | 'json' | To specify the data type in order to parse the callback value if it's text content. Can be left empty if callback value is
| |||||||||||||||
convert-response | uploader.convertResponse | - | Converts response data to standard format that can be consumed by the uploader, in order to allow the uploader to display upload result. The parameter is the callback data. The type of the return value must conform to the following:
Additional fields can be added to the response data. These data fields will be included in the | |||||||||||||||
accept | string | - | The same as the accept attribute of native <input> elements. Works as an extra layer of validation on top of browsers' file filter. Will skip validation when MIME type doesn't match file extension, eg. application/msword . | |||||||||||||||
max-count | number | - | The maximum file count. | |||||||||||||||
max-size | number | string | - | The maximun size of a single file. When being a number , the unit will be byte . When being a string , units can be added after numbers, including b / kb / mb / gb / tb . | |||||||||||||||
payload | Object | - | The extra data payload to be sent together with the file. | |||||||||||||||
progress | string | 'text' | To specify how to display progress when
| |||||||||||||||
autoupload | boolean | true | Whether to start upload as soon as a file is selected. | |||||||||||||||
order | string | asc | The order of displaying uploaded files according to start time.
| |||||||||||||||
upload | function(Object, Object): function | - | Customizing the upload process in case the value of
If | |||||||||||||||
controls | function(Object, Array<Object>): Array<Object> | - | In image upload mode, it is used to customize the actions on the floating toolbar. The parameter types are
|
Slots
Name | Description | |||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
button-label | The content in the upload button. Default content: file upload for prompt to select a file, and image upload for upload image icon. | |||||||||||||||
upload | The area of the upload button in image upload mode. | |||||||||||||||
desc | The content of the prompt for the number, format, size, etc. of files. | |||||||||||||||
file | Single file area to customize the file content.
| |||||||||||||||
file-before | The area before the contents of a single file. The scope argument is the same as the file slot. | |||||||||||||||
file-after | The area after the contents of a single file. The scope argument is the same as the file slot. | |||||||||||||||
uploading | The area of a single image being uploaded in image upload mode. The scope argument is the same as the file slot. | |||||||||||||||
failure | The area of a single image that failed to upload in image upload mode. The scope argument is the same as the file slot. |
Events
Name | Description | |||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
change | Triggers when upload succeeded or a file is removed. The callback parameter list is
| |||||||||||||||||||||||||||||||||||||||||
remove | Triggered when a file is removed. The callback parameter list is
Fields added from | |||||||||||||||||||||||||||||||||||||||||
success | Triggers when upload succeeded. Shares the same callback parameter list with the remove event. | |||||||||||||||||||||||||||||||||||||||||
failure | Triggers when upload failed. Shares the same callback parameter list with the remove event. | |||||||||||||||||||||||||||||||||||||||||
invalid | Triggered when file validation fails. The callback parameter list is
| |||||||||||||||||||||||||||||||||||||||||
statuschange | Triggered when the status of the entire uploader changes. The callback parameter list is
| |||||||||||||||||||||||||||||||||||||||||
progress | Triggered when upload progress updated, when |
Configs
Key | Type | Default | Description |
---|---|---|---|
uploader.requestMode | string | 'xhr' | Same as the request-mode prop. |
uploader.iframeMode | string | 'xhr' | Same as the iframe-mode prop. |
uploader.callbackNamespace | string | 'veuiUploadResult' | Same as the callback-namespace prop. |
uploader.headers | Object | - | Same as the headers prop. |
uploader.convertResponse | function(Object): Object | - | Same as the convert-response prop. |
Icons
Name | Description |
---|---|
upload | Upload file. |
clear | Remove file. |
success | Upload succeeded. |
redo | Retry upload. |
file | File. |
add | Add file. |
alert | Validation failure alert. |