巨坑啊! before-upload返回false 会执行on-remove

通过对on-remove对应参数的打印,发现回调中的file参数有个status,若是是在before-upload中就被过滤了,就是ready,若是已经上传成功了去点击删除,status是success,就他了。

onRemove(file,fileList){if(file.status == 'success'){//删除后改变某些状态的代码}if(file.status == 'ready'){//这里应该就是before-upload中返回false时的状况了,还有没有别的状况,未知}        
}
 handleRemove(file, fileList) {
// console.log('删除图片', file)
// 防止before-upload返回false时,会删除前一个上传成功的图片
if (file.status == 'success') { let url = file.response?file.response.respData.url:file.urlthis.fileList.splice(this.fileList.findIndex(item => item.url == url), 1)this.$emit("update:fileList", this.fileList);}if(file.status == 'ready'){//这里应该就是before-upload中返回false时的状况了,还有没有别的状况,未知} // console.log('删除完后剩下的图片', this.fileList)},

 

<template><div v-loading="isLoading"><el-uploadref="upload" action="/jpark-center-mgr/api/jsis/upload/upload2oss"multiple:limit="3"list-type="picture-card":on-remove="handleRemove":on-preview="handlePictureCardPreview":on-exceed="handleExceed" :on-success="handleSuccess" :on-error="handleError" :before-upload="beforeAvatarUpload":file-list="fileList"><i slot="default" class="el-icon-plus"></i><div class="el-upload__tip" slot="tip">只能上传{{supportFileExt}}文件,最多上传3张图片,且每张图片不超过5MB</div></el-upload><el-dialog :visible.sync="dialogVisible1" append-to-body><img width="100%" :src="dialogImageUrl" alt=""></el-dialog></div>
</template>
<script>import jportalCommon from '@/jportal-common-update'let userStorageService = jportalCommon.userStorageServiceexport default {props: {// limit: {//   type: Number,//   default: 10,//   required: false// },// requestUrl: {//   type: String,//   default: "/jpark-center-mgr/api/jsis/upload/upload2oss",//   required: false// },// supportFileExt: {//   type: String,//   default: "jpg/jpeg/png/doc/docx/xls/xlsx/rar/zip",//   required: false// },// limitFileSize: {//   type: Number,//   default: 10,//   required: false// },fileList: {type: Array,default: function () {return []},required: true}},data() {return {isLoading: false,// 上传图片dialogImageUrl: '',dialogVisible1: false,supportFileExt: "jpg/jpeg/png",limitFileSize: 5, // 5M}},methods: {// 上传图片handleRemove(file, fileList) {// console.log('删除图片', file)if (file.status == 'success') { // 防止before-upload返回false时,会删除前一个上传成功的图片let url = file.response?file.response.respData.url:file.urlthis.fileList.splice(this.fileList.findIndex(item => item.url == url), 1)this.$emit("update:fileList", this.fileList);}if(file.status == 'ready'){//这里应该就是before-upload中返回false时的状况了,还有没有别的状况,未知} // console.log('删除完后剩下的图片', this.fileList)},handlePictureCardPreview(file) {this.dialogImageUrl = file.url;this.dialogVisible1 = true;},handleDownload(file) {console.log(file);},handleExceed(files, fileList) {this.$message({type: 'warning',message: '最多只能上传3个文件'})},handleSuccess(res, file, fileList) {this.isLoading = false;// var temp = {};// temp.name = file.name;// temp.size = Math.round(file.size / 1024);this.fileList.push({url: res.respData.url});// console.log('this.fileList',this.fileList)this.$emit("update:fileList", this.fileList);this.$message({type: 'success',message: '文件上传成功'});},handleError(e, file) {this.isLoading = false;this.$message({type: 'error',message: e});},//上传文件对应的函数beforeAvatarUpload(file) {const surportExt = "."+this.supportFileExt.split("/").join("/.")const isRuleFile = file && file.name && surportExt.indexOf(file.name.substring(file.name.lastIndexOf(".")).toLowerCase()) != -1;const isLt10M = file.size / 1024 / 1024 < this.limitFileSize;if (!isRuleFile) {this.$message.error('请按指定文件格式上传!');}if (!isLt10M) {this.$message.error('上传文件大小不能超过 '+this.limitFileSize+'MB!');}if (isRuleFile && isLt10M) {this.isLoading = true;}return isRuleFile && isLt10M;},clearFiles() {this.fileList = [];this.$refs.upload.clearFiles();}},watch: {},mounted() {}}
</script>
<style scoped>.a-link {color: #030303;text-decoration: none;}.a-link:hover {color: #4E84FE;}.upload-button {width: 90px;height: 90px;background: rgba(78, 132, 254, 1);border-radius: 4px;cursor: pointer;float: left;line-height: 25px;padding-top: 20px;}.upload-tip {float: right;width: 350px;margin-left: 20px;margin-top: 50px;text-align: left;line-height: 20px;}.icon-upload {width: 14px;height: 16px;}.icon-files {width: 15px;height: 17px;cursor: pointer;}.content-font {color: #030303;font-weight: 400;}
</style>

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.hqwc.cn/news/690204.html

如若内容造成侵权/违法违规/事实不符,请联系编程知识网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

LeetCode:116.填充每个节点的下一个右侧节点指针

文章目录 1.层次遍历2.使用next层序遍历3.递归方法 LeetCode&#xff1a;116.填充每个节点的下一个右侧节点指针 题目&#xff1a; 示例&#xff1a; 分析题意容易关注到只需要将每层结点连接起来&#xff0c;因此我们只需要把每层结点求出来即可&#xff0c;即使用层次遍历。 …

【每日刷题】Day37

【每日刷题】Day37 &#x1f955;个人主页&#xff1a;开敲&#x1f349; &#x1f525;所属专栏&#xff1a;每日刷题&#x1f34d; &#x1f33c;文章目录&#x1f33c; 1. 2391. 收集垃圾的最少总时间 - 力扣&#xff08;LeetCode&#xff09; 2. 1614. 括号的最大嵌套深度…

免费AI工具教学知识库

在数字化时代&#xff0c;AI技术正以前所未有的速度改变着世界。你是否也渴望踏入这个充满无限可能的领域&#xff1f;好消息&#xff01;现在有一个免费的AI知识库向你敞开大门&#xff0c;助你轻松掌握AI的奥秘。 这个知识库内容丰富&#xff0c;覆盖从AI入门必学到AI使用进阶…

vue3属性透传(透传 Attributes),支持多个根节点,且可以在JavaScript 中访问透传 Attributes

支持多个根节点&#xff0c;且可以在JavaScript 中访问透传 Attributes Index.vue: <script setup> import { ref, onMounted } from vue import Child from ./Child.vue import ./index.cssconst handleClick () > {console.log(1) }onMounted(() > {}) </s…

【3dmax笔记】036:FDD修改器

一、FDD修改器简介 FDD修改器是对模型进行变形处理的命令,FDD后面的数字越大,编辑节点越多,编辑越精细,但是FDD控制点多的同时,模型上的节点也要多才可以。 FFD修改器是一种非常灵活的修改器,可以让我们对模型进行自由的变形操作。通过在FFD修改器中设置变形点,我们可…

Celery Redis 集群版连接和PyCharm启动配置

目录 使用Redis cluster版作为broker原因 PyCharm配置 使用Redis cluster版作为broker 在celery5及其之前版本&#xff0c;需要配置如下才可行 celery_app.conf.update( broker_transport_options{“global_keyprefix”: “{celery}:”}, ) 原因 https://github.com/celery/…

uniapp音乐播放整理

一、前置知识点 1.1 音频组件控制-uni.createInnerAudioContext() 创建并返回内部 audio 上下文 innerAudioContext 对象。 主要用于当前音乐播放&#xff1b; 1.1.1 innerAudioContext属性 属性类型说明只读平台差异说明srcString音频的数据链接&#xff0c;用于直接播放…

【Python系列】Python中列表属性提取

&#x1f49d;&#x1f49d;&#x1f49d;欢迎来到我的博客&#xff0c;很高兴能够在这里和您见面&#xff01;希望您在这里可以感受到一份轻松愉快的氛围&#xff0c;不仅可以获得有趣的内容和知识&#xff0c;也可以畅所欲言、分享您的想法和见解。 推荐:kwan 的首页,持续学…

【Java 查询树结构列表,递归删除子节点】

Java 获取列表树结构&#xff0c;递归删除子节点 数据库表结构ModelVO查询树结构列表递归删除子节点 数据库表结构 Model Data AllArgsConstructor NoArgsConstructor public class TBaseDept {/** ID */private String id;/** 单位名称 */private String fdName;/** 部门编码…

山东大学软件学院创新项目实训开发日志——第11周

山东大学软件学院创新项目实训开发日志——第11周 项目名称&#xff1a;ModuFusion Visionary&#xff1a;实现跨模态文本与视觉的相关推荐 -------项目目标&#xff1a; 本项目旨在开发一款跨模态交互式应用&#xff0c;用户可以上传图片或视频&#xff0c;并使用文本、点、…

Kafka效率篇-提升效率三板斧

kafka在效率上做了很多的努力。最初的一个使用场景是处理网页上活跃的数据&#xff0c;它往往有非常大的体量&#xff0c;每个页面都能产生数十条写入。而且我们假设每条消息都会被至少一个消费者消费&#xff08;通常是多个&#xff09;&#xff0c;因此&#xff0c;我们努力让…

2 GPIO控制

ESP32的GPIO的模式&#xff0c;一共有输入和输出模式两类。其中输入模式&#xff1a;上拉输入、下拉输入、浮空输入、模拟输入&#xff1b;输出模式&#xff1a;输出模式、开漏输出&#xff08;跟stm32八种输入输出模式有所不同&#xff09;。库函数中控制引脚的函数如下&#…