Skip to content

UploadImage 上传图片

代码演示

基础用法

vue
<script setup>
import { ref } from 'vue'

const images = ref('')
</script>

<template>
  <a-space :size="24">
    <x-upload-image v-model="images" />

    <x-upload-image
      v-model="images"
      :width="200"
    />
  </a-space>
</template>

<style lang="less" scoped></style>

自定义文案

vue
<script setup>
import { ref } from 'vue'

const images = ref('')
</script>

<template>
  <x-upload-image
    v-model="images"
    text="选择图片"
  />
</template>

<style lang="less" scoped></style>

插槽

vue
<script setup>
import { ref } from 'vue'

const images = ref('')
</script>

<template>
  <x-upload-image
    v-model="images"
    :width="240"
  >
    <div class="custom">
      自定义插槽
    </div>
  </x-upload-image>
</template>

<style lang="less" scoped>
.custom {
  width: 240px;
  height: 120px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: @color-border dashed 1px;
  cursor: pointer;
  transition: all 0.15s;

  &:hover {
    border-color: @color-primary;
    color: @color-primary;
  }
}
</style>

裁剪

vue
<script setup>
import { ref } from 'vue'

const images = ref('')
</script>

<template>
  <x-upload-image
    v-model="images"
    :aspect-ratio="1"
    cropper
    text="开启裁剪"
  />
</template>

<style lang="less" scoped></style>

圆角

vue
<script setup>
import { ref } from 'vue'

const images = ref('')
</script>

<template>
  <x-upload-image
    v-model="images"
    round
  />
</template>

<style lang="less" scoped></style>

批量上传

vue
<script setup>
import { ref } from 'vue'

const images = ref([])
</script>

<template>
  <x-upload-image
    v-model="images"
    draggable
    multiple
  />
</template>

<style lang="less" scoped></style>

API

Props

参数说明类型默认值
model-value(v-model)当前输入的值string array-
multiple批量上传booleanfalse
width宽,单位:pxnumber120
height高,单位:pxnumber120
text按钮文字string-
maxSize最大限制string number2M
accept允许上传的文件类型stringimage/*
disabled是否禁用,禁用后无法上传,可以正常回显booleanfalse
round是否圆角booleanfalse
cropper是否开启裁剪booleanfalse
aspect-ratio比例,开启裁剪时有效,详见 Croppernumber0
quality图片质量,开启裁剪时有效,详见 Croppernumber1
draggable拖拽,批量上传有效booleanfalse

Events

事件名说明回调参数
change内容发生改变modelValue

Slots

名称说明
default上传按钮
icon按钮图标
text按钮文字

本文档内容版权为 XYAdmin 作者所有,保留所有权利。