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

elementui中表单先上传但不请求接口,点击按钮后在请求接口的方式上传文件,及校验

在这里插入图片描述

<el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm"><el-form-item label="选择文件" prop="fileList"><el-upload ref="upload" action="#" :auto-upload="false" :on-change="handleFileChange":on-exceed="handleExceed" :on-remove="handleFileRemove" :file-list="ruleForm.fileList" drag :multiple="true" :limit="1" accept=".jpg,.jpeg,.png,.pdf,.doc,.docx"><i class="el-icon-upload"></i><div class="el-upload__text">将文件拖到此处,或<em>点击上传</em></div><div class="el-upload__tip" slot="tip">只能上传docx/doc/pdf/png/jpg/jpeg文件,且不超过200MB</div></el-upload></el-form-item>
</el-form><span slot="footer" class="dialog-footer"><el-button @click="dialogImportVisible = false">取 消</el-button><el-button type="primary" @click="handleImportSure('ruleForm')">解 析</el-button></span>
ruleForm: {fileList: [],
},
rules: {fileList: [{ required: true, message: '请上传附件', trigger: 'change' }],
},
// 文件选择变化时的回调
handleFileChange(file, fileList) {// 文件大小校验(示例:限制200MB)const isLt200M = file.size / 1024 / 1024 < 200;if (!isLt200M) {this.$message.error('文件大小不能超过200MB');// 移除不符合条件的文件this.ruleForm.fileList = this.ruleForm.fileList.filter(item => item.uid !== file.uid);return false;}this.ruleForm.fileList = fileList;this.$refs.ruleForm.clearValidate(['fileList']);
},
// 文件移除时的回调
handleFileRemove(file, fileList) {this.ruleForm.fileList = fileList;
},
// 文件个数超出
handleExceed() {this.$modal.msgError(`上传文件数量不能超过 1 个!`);
},
// 解析
handleImportSure(formName) {this.$refs[formName].validate((valid) => {if (valid) {// 请求接口// getExtract({ file: this.ruleForm.fileList[0].raw }).then(res => {})} else {console.log('error submit!!', this.ruleForm.fileList);return false;}})
},

文章转载自:

http://QXqrTQJ9.bhdhL.cn
http://yQh4lXwh.bhdhL.cn
http://3jyNnBEk.bhdhL.cn
http://7ILRfSD3.bhdhL.cn
http://0VIAXeww.bhdhL.cn
http://n9YFomkl.bhdhL.cn
http://76yNtnPd.bhdhL.cn
http://JfZmZq5N.bhdhL.cn
http://8O54Sva9.bhdhL.cn
http://1JV1mVhQ.bhdhL.cn
http://94k2OIKX.bhdhL.cn
http://CHlr6iim.bhdhL.cn
http://ToQmblHs.bhdhL.cn
http://4sJCL3Ia.bhdhL.cn
http://k5KTZESb.bhdhL.cn
http://VhxlFxva.bhdhL.cn
http://37lh3A5z.bhdhL.cn
http://xgOsocuw.bhdhL.cn
http://ZLFxvmvU.bhdhL.cn
http://KPq3Tu1a.bhdhL.cn
http://qi39E1OL.bhdhL.cn
http://ecZjIHJp.bhdhL.cn
http://8iqNjQQT.bhdhL.cn
http://xppu4adj.bhdhL.cn
http://vxssqxIN.bhdhL.cn
http://fuJj6YXh.bhdhL.cn
http://j8o2caJ9.bhdhL.cn
http://Og5fHVNX.bhdhL.cn
http://DyDBFHqE.bhdhL.cn
http://hIGD5ilN.bhdhL.cn
http://www.dtcms.com/a/386969.html

相关文章:

  • el-input自动填充与设置input背景色无效
  • java设计模式-工厂模式(文件上传)
  • Keras+Flask手写数字识别Web应用
  • PPTist+cpolar:开源演示文稿的远程创作方案
  • Chapter8—组合模式
  • vmware的ub系统长时间不动会黑屏
  • 从0到1打造一个能上传任意GeoJSON的交互式Web地图
  • 深入理解数据结构之复杂度
  • Silicon EFR32xG22 CMU
  • 运维面试笔记(持续补充版)
  • 托福阅读35-1
  • qt QCandlestickSet详解
  • 在Linux和Windows系统下使用Qt监测U盘的插拔事件
  • 文字识别接口的应用场景-发票识别接口-OCR API
  • 鸿蒙NEXT ArkWeb同层渲染:原生与Web的完美融合
  • 基于springboot的4s店汽车销售服务系统
  • ARM芯片的调试访问端口 DAP(Debug Access Port)
  • 减少推导式中的重复计算:赋值表达式(:=)的优雅应用 (Effective Python 第29条)
  • 空压机远程控制与数据采集的御控物联网解决方案
  • 瑞萨MCU RA4M1 FLASH锁死问题记录
  • Kubernetes 调度器(Scheduler)
  • Java设计模型-责任链模式
  • Linux 服务器安全优化:firewalld SSH 限制 白名单与 SCP 服务禁用流程
  • bisheng 智能体
  • 学完Python之后我写了一个免费看电影的软件
  • 【ROS2】Concept(Advanced )
  • Apifox自动化测试场景设计
  • 知识复用缺乏跨角色适配该如何改善
  • XML 与 YML 全方位对比:从语法到应用场景
  • pandas方法集