Skip to content

Upload

A file/image/video upload component that supports multiple selection, compression, preview, custom upload logic, and more.

  • Supports image, video, and file upload types
  • Supports multiple selection and count limits
  • Supports image compression
  • Supports custom upload logic
  • Supports disabled and readonly states

Notice

This component may have slight behavioral differences across platforms. Please refer to the actual rendered result.

Platform Differences

App (vue)App (nvue)H5Mini Program

Basic Usage

  • Bind the file list via v-model, which defaults to an empty array.
  • Set the accepted file type via accept, which defaults to image.
html
<see-upload v-model="fileList" />

<script lang="ts" setup>
import { ref } from 'vue';
const fileList = ref([]);
</script>

Multiple Upload

  • Enable multiple selection by setting isMultiple to true.
  • Set the maximum file count via maxCount, which defaults to 9.
html
<see-upload v-model="fileList" isMultiple :maxCount="9" />

<script lang="ts" setup>
import { ref } from 'vue';
const fileList = ref([]);
</script>

File Size Limit

  • Set the maximum file size via maxSize in MB.
  • The onOversize event is triggered when a file exceeds the limit.
html
<see-upload v-model="fileList" :maxSize="5" @on-oversize="handleOversize" />

<script lang="ts" setup>
import { ref } from 'vue';
const fileList = ref([]);

const handleOversize = (file) => {
  console.log('File size exceeds the limit', file);
};
</script>

Video Upload

  • Set accept to video to upload video files.
  • Set it to media to support both images and videos.
html
<see-upload v-model="fileList" accept="video" :maxCount="3" />

<script lang="ts" setup>
import { ref } from 'vue';
const fileList = ref([]);
</script>

Custom Upload

  • Pass a custom upload function via the upload prop that returns the file URL.
  • Use beforeRead to validate before uploading.
  • Use afterRead to execute a callback after uploading.
html
<see-upload
  v-model="fileList"
  :upload="customUpload"
  :before-read="beforeRead"
  :after-read="afterRead"
/>

<script lang="ts" setup>
import { ref } from 'vue';
const fileList = ref([]);

const customUpload = async (file) => {
  // Custom upload logic, returns the file URL
  const url = await uploadToServer(file);
  return url;
};

const beforeRead = (file) => {
  // Return false to prevent upload
  return file.size < 10 * 1024 * 1024;
};

const afterRead = (file) => {
  console.log('Upload complete', file);
};
</script>

Disabled and Readonly

  • Disable the upload by setting isDisabled to true.
  • Set readonly mode by setting isReadonly to true, which allows preview but prevents adding or deleting files.
html
<see-upload v-model="fileList" isDisabled />
<see-upload v-model="fileList" isReadonly />

Image Compression

  • Enable image compression by setting isCompress to true, which is enabled by default.
  • Set the compression quality via compressQuality, ranging from 0 to 100, defaulting to 80.
html
<see-upload v-model="fileList" isCompress :compressQuality="60" />

API

Props

ParameterDescriptionTypeDefaultOptional Values
modelValueFile listUploadFileItem[][]-
acceptAccepted file type'image' | 'video' | 'file' | 'media''image'-
isMultipleWhether to enable multiple selectionbooleanfalse-
maxCountMaximum file countnumber9-
maxSizeMaximum file size per file (MB)number--
isDisabledWhether disabledbooleanfalse-
isReadonlyWhether readonlybooleanfalse-
isDeletableWhether to show the delete buttonbooleantrue-
isPreviewWhether to support previewbooleantrue-
isCompressWhether to compress imagesbooleantrue-
compressQualityCompression quality (0-100)number80-
uploadCustom upload function(file) => Promise<string>--
beforeReadValidation before reading(file) => boolean | Promise<boolean>--
afterReadCallback after reading(file) => void--
nameForm field namestring''-
sizeSize'small' | 'default' | 'large''default'-
uploadTextUpload button textstring''-

UploadFileItem Type

ParameterDescriptionType
urlFile URLstring
nameFile namestring
sizeFile sizenumber
typeFile typestring
statusUpload status'uploading' | 'done' | 'error'
messageStatus messagestring
progressUpload progress (0-100)number

Events

EventDescriptionCallback Parameters
onChangeTriggered when the file list changesfiles: UploadFileItem[]
onOversizeTriggered when a file exceeds the size limitfile: UploadFileItem
onDeleteTriggered when a file is deletedfile: UploadFileItem, index: number
onPreviewTriggered when a file is previewedfile: UploadFileItem, index: number
onClickUploadTriggered when the upload button is clickedevent: Event
onErrorTriggered when an upload error occurserror: Error

Slots

SlotDescription
defaultCustom upload area content
previewCustom preview content
preview-deleteCustom delete button content

Liao ICP No. 2025070134