Skip to content

ImageUpload

EasyImageUpload is an image upload component based on Element Plus Upload component, optimized for image upload scenarios.

Online Demo

请上传 大小不超过 2MB 格式为 png/jpg/jpeg 的文件
绑定值:
<template>
  <div class="demo-upload">
    <easy-image-upload
      v-model="imageList"
      action="https://run.mocky.io/v3/9d059bf9-4660-45f2-925d-ce80ad6c4d15"
      :limit="3"
      :file-size="2"
    />
    <div style="margin-top: 20px">绑定值: {{ imageList }}</div>
  </div>
</template>

<script setup>
import { ref } from "vue"
import { EasyImageUpload } from "easy-elplus"

const imageList = ref("")
</script>

<style scoped>
.demo-upload {
  width: 100%;
}
</style>

API

Attributes

AttributeDescriptionTypeDefault
v-modelBinding value, supports comma-separated string, object, or arrayString / Object / Array
actionUpload URL (Required)String
limitMax upload countNumber5
file-sizeImage size limit (MB)Number5
file-typeAllowed image extensionsArray["png", "jpg", "jpeg"]
is-show-tipWhether to show upload tipBooleantrue
headersRequest headers for uploadObject{}
base-urlBase URL. Attempts to remove this prefix when saving after successful upload; concatenates this prefix when displaying if not an absolute pathString""
check-successCustom success check function, accepts response object as parameterFunctionres => res.code === 200 || res.success === true
response-pathPath to image URL in response, supports deep nesting (e.g. data.url)String"data"
error-fieldPath to error message in responseString"msg"

Events

Event NameDescriptionCallback Parameters
update:modelValueTriggered when binding value changes(value: string)

Features

  1. Auto Preview: Click the thumbnail of uploaded image to view full image preview.
  2. Hide Upload Button: Automatically hides the upload button when the number of uploaded images reaches limit.
  3. Format Validation: Defaults to only allow png, jpg, jpeg formats.
  4. Path Handling: Flexible handling of relative paths returned by backend with base-url.