使用el-upload添加除预览+删除之外的功能图标按钮

发布时间:2026/11/5 3:22:09
使用el-upload添加除预览+删除之外的功能图标按钮 **需求**使用el-upload添加除预览删除之外的添加索引设置小图标按钮实现效果如图分别为未添加图片、添加图片、添加图片为设置限制数量5时添加按钮隐藏结构代码如下el-form-item label图片propgasProductFileRelationVOListel-upload v-model:file-listformMethod.fileListaction#accept.png,.jpg,.jpeglist-typepicture-card:limit5:auto-uploadfalse:on-changeformMethod.fileChange:on-exceedformMethod.handleExceed:classformMethod.fileList.length 5? appl_upload applet_upload: appl_uploadel-iconPlus//el-icon!--自定义文件列表的展示--template #file{ file }divimgclassel-upload-list__item-thumbnail:srcfile.urlalt/spanclassel-upload-list__item-actionsspanclassel-upload-list__item-previewclickdialogObj.openDialog(file)el-iconzoom-in//el-icon/spanspanclassel-upload-list__item-deleteclickformMethod.handleRemove(file)el-iconDelete//el-icon/span/spanspanclassindex_setspan v-iffile.indexPicimg src/assets/images/indexSet.pngalt/索引/spanspan v-elseclickformMethod.setIndex(file)设为索引/span/span/div/templatetemplate #tipdiv stylecolor: #da2d2av-ifformMethod.fileList.length ! 5文件大小不能超过10M/div/template/el-upload/el-form-item//图片放大预览弹框el-dialog title图片v-modeldialogObj.dialogImagVisibleappend-to-bodyimg stylewidth: 100%:srcdialogObj.dialogImageUrlalt//el-dialog2、js相关代码// 表单用到的方法letformMethodreactive({loading:false,// 图片fileList:[],fileChange:(file,fileList){if(![image/jpeg,image/jpg,image/png].includes(file.raw.type)){ElMessage.error(图片格式有误);if(formMethod.fileList.length!0){formMethod.fileList.forEach((item,index){if(item.statusready){formMethod.fileList.splice(index,1);}});}return;}if(file.size/1024/102410){ElMessage.error(图片大小不能超过10MB请重新上传);if(formMethod.fileList.length!0){formMethod.fileList.forEach((item,index){if(item.statusready){formMethod.fileList.splice(index,1);}});}return;}// 上传接口constfdnewFormData();fd.append(file,file.raw);uploadFile(fd).then((res){// 调用后台给的上传图片接口if(res.code200){letindexPic0;if(formMethod.fileList.length1){indexPic1;}formMethod.fileList.push({fileId:res.data.id,id:res.data.id,url:res.data.visitUrl,name:res.data.originalName,filePath:res.data.filePath,visitUrl:res.data.visitUrl,indexPic:indexPic,});if(formMethod.fileList.length!0){formMethod.fileList.forEach((item,index){if(item.statusready){formMethod.fileList.splice(index,1);}});}ElMessage.success(上传成功);}else{formShop.gasProductFileRelationVOList[];formMethod.fileList[];}});},//将图片设为索引setIndex:(file){formMethod.fileList.forEach((item){item.indexPic0;});file.indexPic1;},handleRemove:(file){letindexformMethod.fileList.indexOf(file);if(index!-1){formMethod.fileList.splice(index,1);}},handleExceed:(fileList){constfilefileList[0];file.uidgenFileId();},// 获取图片getPic:(){formShop.gasProductFileRelationVOList[];if(formMethod.fileList.length!0){formMethod.fileList.forEach((item){formShop.gasProductFileRelationVOList.push({id:item.id,fileId:item.fileId,indexPic:item.indexPic,});});}},// 表单提交方法submit:(operType){formMethod.getPic();form.value.validate((valid){if(valid){//表单提交接口}});},});// 图片放大letdialogObjreactive({dialogImagVisible:false,dialogImageUrl:,openDialog:(file){dialogObj.dialogImageUrlfile.url;dialogObj.dialogImagVisibletrue;}});

关于本文作者

来自尧图内容编辑团队

尧图内容编辑团队 内容团队

尧图内容编辑团队

本文由尧图网络内容编辑团队执笔。团队由资深项目经理、前端工程师与设计师组成,所有内容均来自亲手交付的真实项目,先讲清问题、再给出可落地的解法。尧图深耕北京网站建设十年,服务过京华建材集团、智造科技等各行业客户,把一线经验沉淀为可复用的行业观察。

  • 十年建站经验,覆盖建材、制造、服务、文创等
  • 项目经理把关选题与事实准确性
  • 工程师与设计师联合撰写专业细节
  • 统一编辑规范,保证文风与排版一致
  • 每月复盘转化数据,迭代选题方向

延伸阅读

相关资讯与近期热门内容

深度阅读推荐

建站决策前值得细读的三篇

网站改版的5个关键决策
2024-08-12

网站改版的5个关键决策

什么时候该改版、改到什么程度、如何避免流量掉光,京华建材集团改版复盘给出答案。

获取专属建站方案

看完文章,把您的行业与预算告诉我们,免费获取一份量身定制的官网建设方案与报价。

立即免费咨询