Skip to content

t-upload

Upload 上传

组件介绍

t-upload 是用于图片/文件上传的组件,支持图片选择、预览、删除等功能。组件仅返回文件选择列表,上传逻辑需要自行编写。支持阿里云 OSS 等云存储上传,可判断是否重复上传以节省存储空间。

平台兼容

HarmonyH5AndroidiOS小程序UTS

基础用法

基础用法参考 demo/upload/upload.uvue

vue
<template>
  <view class="upload-demo">
    <!-- 单图上传 -->
    <t-upload v-model="image1" :count="1"></t-upload>
    
    <!-- 多图上传 -->
    <t-upload 
      v-model="images" 
      :count="9"
      :previewImage="true">
    </t-upload>
    
    <!-- 自定义样式 -->
    <t-upload 
      v-model="images2" 
      :count="6"
      type="primary"
      icon="camera-fill"
      itemBoxClass="custom-box">
    </t-upload>
    
    <!-- 不显示删除按钮 -->
    <t-upload 
      v-model="images3" 
      :count="3"
      :closed="false">
    </t-upload>
  </view>
</template>

<script setup>
const image1 = ref([]);
const images = ref([]);
const images2 = ref([]);
const images3 = ref([]);
</script>

<style scoped>
.upload-demo {
  padding: 40rpx;
}
.upload-demo t-upload {
  margin-bottom: 40rpx;
}
</style>

Props

属性名说明类型默认值
modelValue选中文件列表UTSJSONObject[][]
count最大上传数量,-1 表示不限制number1
closed是否显示关闭(删除)图标booleantrue
closeIcon移除图片的图标名称string'closes-fill'
closeIconClass移除图标的样式string''
icon添加按钮图标string'add-fill'
iconClass图标样式string''
itemBoxClass每一项盒子的样式string''
stateBoxClass状态进度显示盒子的样式string''
sourceType图片或视频拾取模式,可选 cameraalbumstring[]['album', 'camera']
sizeType压缩模式,可选 originalcompressedstring[]['original', 'compressed']
previewImage是否支持预览booleantrue
path点击组件后跳转的页面路径string''
hover是否启用点击效果booleanfalse
type组件主题类型string'primary'
disabled是否禁用booleanfalse
effect组件显示主题string'normal'
size组件尺寸,可选 largemediumsmallministring'medium'

Events

事件名说明回调参数
update:modelValue文件列表变化时触发UTSJSONObject[]
change选择文件变化时触发UTSJSONObject[]
click点击时触发event
initFinished组件初始化完成触发组件节点信息
touchstart触摸开始时触发event
touchend触摸结束时触发event
touchmove触摸移动时触发event
touchcancel触摸取消时触发event

外部类

类名说明
close-icon-class关闭图标样式
icon-class添加图标样式
item-box-class每一项盒子样式
state-box-class状态显示盒子样式

数据格式

typescript
interface UploadFile {
  path: string;      // 本地临时路径
  url?: string;      // 上传后的网络地址
  name?: string;     // 文件名
  size?: number;     // 文件大小
  type?: string;     // 文件类型
  status?: {         // 上传状态
    icon?: string;   // 状态图标
    text?: string;   // 状态文本
  };
}

插槽

插槽名说明
icon自定义添加按钮图标
state自定义状态显示内容