当前位置: 首页 > news >正文

基于uniapp(vue3)H5附件上传组件,可限制文件大小

代码:

<template><view class="upload-file"><text>最多上传5份附件,需小于50M</text><view class="" @click="selectFile">上传</view></view><view class="list" v-if="fileListName.length"><view class="file-item" v-for="(item,index) in fileListName"><view class="_text_box">{{item}}</view><view @click="delFile(index)"><u-icon name="close-circle" color="red"></u-icon></view></view></view>
</template><script setup>import {ref} from "vue";const props = defineProps({// 文件最大体积(mb)maxsize: {type: [String, Number],default: 50}})const fileList = ref([])const fileListName = ref([])function selectFile() {uni.chooseFile({success: (chooseImageRes) => {const tempFilePaths = chooseImageRes.tempFilePaths;console.log("----", props.maxsize);console.log("----", chooseImageRes);if (chooseImageRes.tempFiles[0].size > (props.maxsize * 1024 * 1024)) {uni.showToast({icon: "none",title: "文件过大"})return}// uni.uploadFile({// 	url: '', // 	filePath: tempFilePaths[0],// 	name: 'file',// 	formData: {// 		'user': 'test'// 	},// 	success: (uploadFileRes) => {// 	}// });fileListName.value.push(chooseImageRes.tempFiles[0].name)}});}function delFile(index) {fileListName.value.splice(index, 1)}
</script><style lang="scss" scoped>.upload-file {width: 100%;display: flex;justify-content: space-between;align-items: center;text {font-size: 24rpx;font-weight: 400;color: #D8D8D8;}&>view {background: #6D76FF;border-radius: 16rpx 16rpx 16rpx 16rpx;width: 110rpx;height: 50rpx;text-align: center;line-height: 50rpx;color: #fff;}}.file-item {width: 100%;display: flex;justify-content: space-between;&>view:nth-child(1) {max-width: 500rpx;text-align: left;}}
</style>

http://www.lryc.cn/news/392510.html

相关文章:

  • Phoenix Omid Timestamp Oracle 组件实现原理
  • Lex Fridman Podcast with Andrej Karpathy
  • 力扣1895.最大的幻方
  • 【C++】 解决 C++ 语言报错:Segmentation Fault
  • 【linuxC语言】手撕Http协议之程序框架
  • 溶解氧(DO)理论指南(1)
  • Mysql中常用函数的使用示例
  • 开源205W桌面充电器,140W+65W升降压PD3.1快充模块(2C+1A口),IP6557+IP6538
  • Java中的内存数据库与缓存技术
  • GUKE万能工具箱(附带源码)
  • FFmpeg开发笔记(四十二)使用ZLMediaKit开启SRT视频直播服务
  • spring-boot-starter-data-redis是否支持reactive响应式编程
  • Java后端每日面试题(day3)
  • [单master节点k8s部署]18.监控系统构建(三)Grafana安装
  • 【JavaScript脚本宇宙】优化你的Web色彩:精选JavaScript颜色工具对比
  • 用html+css设计一个列表清单小卡片
  • day11_homework_need2submit
  • 昇思MindSpore学习总结九——FCN语义分割
  • js数据库多级分类按树形结构打印
  • centos下编译安装redis最新稳定版
  • 如何让自动化测试更加灵活简洁?
  • linux 下载依赖慢和访问github代码慢
  • 奥比中光astra_pro相机使用记录
  • 【MindSpore学习打卡】应用实践-计算机视觉-深入解析 Vision Transformer(ViT):从原理到实践
  • Debezium系列之:支持在一个数据库connector采集中过滤某些表的删除事件
  • SQL Server端口配置指南:最佳实践与技巧
  • FastGPT 报错:undefined 该令牌无权使用模型:gpt-3.5-turbo (request id: xxx)
  • springboot系列八: springboot静态资源访问,Rest风格请求处理, 接收参数相关注解
  • # 职场生活之道:善于团结
  • go sync包(五) WaitGroup