Skip to content

UploadFile

File upload, always useful.

Type Definitions

ts
/**
 * File list type
 * @property name File name
 * @property url File path
 */
interface FileInfo {
  /** File name */
  name: string;
  /** File path */
  url: string;
}
ts
/**
 * Removed file type
 * @property idx File index
 * @property name File name
 * @property url File path
 */
interface RemoveFile {
  /** File name */
  name: string;
  /** File path */
  url: string;
  /** File index */
  idx: number;
}

Basic Usage

vue
<template>
  <UploadFile
    :value="imgUrl"
    :limit="1"
    @upload="(val) => (imgUrl = val.url)"
    @remove="imgUrl = ''"
  />
</template>

<script setup lang="ts">
const imgUrl = ref<string>(""); // Image URL, string type
</script>
vue
<template>
  <UploadFile
    :value="imgUrls"
    @upload="(val) => imgUrls.push(val.url)"
    @remove="
      (val) => {
        if (imgUrls[idx] === val.url) {
          imgUrls.splice(idx, 1);
        }
      }
    "
  />
</template>

<script setup lang="ts">
const imgUrls = ref<string[]>([]); // Image URLs, array type
</script>

💡 Tip

This is just a common usage. For more, see example

Props

NameTypeRequiredDefaultDescription
valuestring[]
string
FileInfo[]
FileInfo
No[]File list
dataObjectNo{}Data to be attached to the form submission
nameStringNofileParameter name for uploaded file
limitNumberNo10File upload quantity limit
max-file-sizeNumberNo10Maximum allowed size for a single file
acceptStringNoimage/*Allowed file types, see accept
typeNUpload[list-type]Noimage-cardBuilt-in style for file list
multipleBooleanNotrueWhether to support multiple selection, invalid when limit is 1
dragBooleanNofalseWhether to support drag upload
drag-optionsDragOptionsNoDragOptionsDrag upload configuration, only valid when drag is true
OthersUpload-PropsNoNUpload component props

DragOptions

NameTypeDefaultDescription
iconStringep:upload-filledIcon
iconSizeNumber50Icon size
titleStringClick here or drag files to this area to uploadTitle

Slots

NameParamsDescription
default()Default slot, trigger, etc.

Events

NameTypeDescription
upload(val: FileInfo) => valCallback for successful file upload
remove(val: RemoveFile) => valCallback for file removal

Contributors

Changelog

Released under the MIT License