Uploader

Demos

File upload

Set type prop to file to use the file upload mode.

  • demo-file1.txt
  • demo-file2.txt
<template>
<article>
  <veui-uploader
    v-model="files"
    action="https://app.fakejson.com/q/ELymQ7xh?token=AWFkjMICPSAB_bO_z-Lnog"
  />
</article>
</template>

<script>
import Uploader from 'veui/components/Uploader'

export default {
  components: {
    'veui-uploader': Uploader
  },
  data () {
    return {
      files: [
        {
          name: 'demo-file1.txt'
        },
        {
          name: 'demo-file2.txt'
        }
      ]
    }
  }
}
</script>

Image upload

Set type prop to image to use the image upload mode.

<template>
<article>
  <veui-uploader
    v-model="images"
    type="image"
    action="https://app.fakejson.com/q/ELymQ7xh?token=AWFkjMICPSAB_bO_z-Lnog"
    ui="horizontal"
  />
</article>
</template>

<script>
import Uploader from 'veui/components/Uploader'

export default {
  components: {
    'veui-uploader': Uploader
  },
  data () {
    return {
      images: [
        {
          src: '/images/content/uploader/demo-image1.jpg'
        },
        {
          src: '/images/content/uploader/demo-image2.jpg'
        }
      ]
    }
  }
}
</script>

API

Props

NameTypeDefaultDescription
typestring'file'

The type of the uploader.

ValueDescription
fileFile upload.
imageImage upload.
valueObject|Array<Object>-
max-countType
1Object
> 1, or nullArray<Object>

The type of single file is {name: string, src: string, ...}, and fields added inside convert-response.

namestring'file'The name of native <input> elements.
actionstring-Upload URL.
headersObjectuploader.headersExtra HTTP headers. Can be globally configured.
with-credentialsbooleantrueThe same as the with-credentials option of XMLHttpRequest.
request-modestringuploader.requestMode

The request mode of the uploader. Can be globally customized.

ValueDescription
xhrUpload with XMLHttpRequest.
iframeUpload with <iframe>.
iframe-modestringuploader.iframeMode

To specify the callback mode when request-mode is iframe. Can be globally customized.

ValueDescription
postmessageCallback with PostMessage.
callbackCallback with callback functions registered according to callback-namespace on window.
callback-namespacestringuploader.callbackNamespaceThe 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-typestring'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 Object.

ValueDescription
jsonThe callback text is JSON.
textThe callback text is plain text.
convert-responseuploader.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:

PropertyTypeDescription
successbooleanWhether the upload succeeded.
namestring=The name of the file. Required when success is true.
srcstring=The location of the file. Required when success is true.
messagestring=Error message when upload fails. Required when success is false.

Additional fields can be added to the response data. These data fields will be included in the value prop and parameter of callbacks change, success, failure, remove and progress events. Can be globally configured.

acceptstring-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.
extensionsArray<string>['jpg', 'jpeg', 'gif', 'png', 'bmp', 'tif', 'tiff', 'webp', 'apng', 'svg']To specify all valid file extensions when accept is set to values like 'image/*'.
uistring-

Style variants.

ValueDescription
horizontalHorizontal style.
max-countnumber-The maximum file count.
max-sizenumber|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.
payloadObject-The extra data payload to be sent together with the file.
progressstring'text'

To specify how to display progress when request-mode is xhr.

ValueDescription
textDisplays as status text.
numberDisplays the progress as percentage.
barDisplays th progress as a progress bar.
autouploadbooleantrueWhether to start upload as soon as a file is selected.
orderstringasc

The order of displaying uploaded files according to start time.

ValueDescription
ascAscending order.
descDescending order.

Slots

NameDescription
button-label

The content of the uploader button. Suggests to select a file by default.

descDescriptions of th uploader, usually maximum file count, size or valid formats.
type-invalid

The content of invalid type error message. Suggests the type being invalid by default.

size-invalid

The content of invalid size error message. Suggests the size being invalid by default.

count-overflow

The content displayed when file count exceeds limit. Suggests too many files by default.

success-label

The content of upload success message. Suggests upload succeeded by default.

failure-label

The content of upload failure message. Suggests upload failed by default.

uploading-label

The content displayed during upload when the progress prop is set to text. Suggests uploading by default.

file

The content of each file.

NameTypeDescription
namestringThe name of the file.
srcstringThe location of the file.
statusstringThe status of the file. Can be one of 'success'/'uploading'/'failure'.
indexnumberThe index of the file within the file list.
file-beforeThe content before each file. Shares the same slot properties with slot `file'.
file-afterThe content after each file. Shares the same slot properties with slot `file'.
extra-operationThe content of extra operatins when under image upload mode, eg. custom buttons. Shares the same slot properties with slot `file'.

Events

NameDescription
change

Triggers when upload succeeded or a file is removed. The callback parameter list is (value).

NameTypeDescription
valueObject|Array<Object>The value of the component.
remove

Triggered when a file is removed. The callback parameter list is (file, index).

NameTypeDescription
fileObjectThe removed file object.
indexnumberThe index of the removed file.

file properties

NameTypeDescription
namestringThe name of the file.
srcstringThe location of the file.
statusstringThe status of the upload process. Can be one of 'success'/'uploading'/'failure'.

Fields added from convert-response are also available.

successTriggers when upload succeeded. Shares the same callback parameter list with the remove event.
failureTriggers when upload failed. Shares the same callback parameter list with the remove event.
statuschange

Triggered when the status of the entire uploader changes. The callback parameter list is (status: string).

ValueDescription
emptyNo file is selected.
uploadingAt least one file is being uploaded.
failureAny file is not being successfully uploaded.
successAll files are successfully uploaded.
progress

Triggered when upload progress updated, when request-mode is 'xhr'. The callback parameter list is (file, index, event).

NameTypeDescription
fileObjectSame as the file parameter of the callback for the remove event.
indexnumberThe index of the file being uploaded.
eventEventNative upload progress event object.

Global config

KeyTypeDefaultDescription
uploader.requestModestring'xhr'Same as the request-mode prop.
uploader.iframeModestring'xhr'Same as the iframe-mode prop.
uploader.callbackNamespacestring'veuiUploadResult'Same as the callback-namespace prop.
uploader.headersObject-Same as the headers prop.
uploader.convertResponsefunction(Object): Object-Same as the convert-response prop.

Icons

NameDescription
uploadUpload file.
clearRemove file.
successUpload succeeded.
redoRetry upload.
fileFile.
addAdd file.
alertValidation failure alert.