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

vue2上传图片

效果图

file-list动态属性绑定,因为 partnerInfo 配置了多个上传字段(比如 logo、license 等),每个字段对应不同的图片列表。

<el-upload
ref="upload"
action="string"
list-type="picture-card"
accept=".jpg,.jpeg,.png,.bmp,.gif"
:http-request="($event)=>uploadStartImage(item.prop,$event)"
:show-file-list="true"
:file-list="partnerInfo[item.prop]"
:on-preview="($event)=>handlePictureCardPreview(item.prop,$event)"
:on-remove="($event)=>handleRemove(item.prop,$event)"
class="custom-upload-container"
>
<div class="upload-img"><img style="width: 145px; height: 145px;"src="@/assets/trace/upload-img.png"alt=""/>
</div>
</el-upload><el-dialog :visible.sync="dialogVisible" center top="0vh" style="max-height:800px overflow-y: auto; scrollbar-width: none;"><img :src="dialogImageUrl" alt="" style="width: 100%; height:800px" ></el-dialog>
uploadStartImage(pro,param) {let formData = new FormData();formData.append("file", param.file); // 要提交给后台的文件formData.append("scene", "other"); // 上传类型this.loading = true;this.loadingText="上传中"uploadFile(formData).then( res => {if(res && res.url &&res.url.length>0){if(pro=='businessLicense'){//营业执照let newList = [...this.partnerInfo.businessLicense]// 添加返回后的文件信息newList.push({ ...res,attachPath: res.url, attachName: res.name, attachType: res.ext })this.$set(this.partnerInfo,'businessLicense',newList)}else{let newList = [...this.partnerInfo.otherQualifications]//添加返回后的文件信息newList.push({ ...res,attachPath: res.url, attachName: res.name, attachType: res.ext })this.$set(this.partnerInfo,'otherQualifications',newList)}this.$modal.msgSuccess("上传成功")setTimeout(()=>{this.loading = false;},1000)}else{this.$modal.msgError("上传失败")this.loading = false;}}).catch(error => {this.loading = false;})},
    handleRemove(prop,file, fileList){if(prop == 'businessLicense'){const newArr = this.partnerInfo.businessLicense.filter(item => item.uid !== file.uid);this.$set(this.partnerInfo,'businessLicense',newArr)}else{const newArr = this.partnerInfo.otherQualifications.filter(item => item.uid !== file.uid);this.$set(this.partnerInfo,'otherQualifications',newArr)}},handlePictureCardPreview(pro,file) {console.log(file,'file.url');this.dialogImageUrl = file.url;this.dialogVisible = true;}  

http://www.xdnf.cn/news/10828.html

相关文章:

  • matlab实现求解兰伯特问题
  • Filebeat技术之多行采集
  • java-spring
  • Blinko智能笔记系统实现跨平台同步与隐私保护的完整技术方案解析
  • 2025年MathorCup数学建模D题短途运输货量预测及车辆调度问题解题文档与程序
  • dataX(入门,mysql到doris)
  • 软件评测师 案例真题笔记
  • RDMA简介1之RDMA开发必要性
  • Java 中执行命令并使用指定配置文件的最佳实践
  • [蓝桥杯]生物芯片
  • 今日主题二分查找(寻找峰值 力扣162)
  • 初识小智AI项目
  • 酵母杂交那些事儿(一)
  • [Python] struct.unpack() 用法详解
  • 在 Linux 上安装 Nmap 工具
  • CSRF攻击与防御
  • 现代密码学介绍
  • 前端开发处理‘流式数据’与‘非流式数据’,在接收完整与非完整性数据时应该如何渲染和使用
  • 【产品研究】安克创新公司产品研究
  • 推荐算法八股
  • STM32外部中断(EXTI)以及旋转编码器的简介
  • 【深度学习-Day 22】框架入门:告别数据瓶颈 - 掌握PyTorch Dataset、DataLoader与TensorFlow tf.data实战
  • MongoTemplate常用api学习
  • [手写系列]从0到1开发并上线Edge浏览器插件
  • AJ-Report
  • 深拷贝与浅拷贝的区别?如何手写实现一个深拷贝?
  • 英语写作中“不少于(小于)”no less than替代no fewer than的用法
  • 【文献精读】Explaining grokking through circuit efficiency
  • virtualbox安装扩展工具以支持共享文件夹
  • Foundation Models for Generalist Geospatial Artificial Intelligence论文阅读