element-ui 文件上传
<el-form-item> <el-upload ref="upload" class="upload-demo" :action="daoruUrls" :on-preview="handlePreview" :on-remove="handleRemove" :file-list="fileArr" :on-success="handleSuccess" :before-upload="beforeUploadFile" :auto-upload="false" :data="daoru" :limit="1" :on-exceed="onexceed" > <el-button slot="trigger" size="small" type="primary">选取文件</el-button> <el-button style="margin-left: 10px;" size="small" type="success" @click="daorusubmitForm('daoruForm')" >导入</el-button> <!-- <div slot="tip" class="el-upload__tip">只能上传jpg/png文件,且不超过500kb</div> --> </el-upload> </el-form-item>
// 导入确认 daorusubmitForm(form) { console.log('111', this.fileArr) // console.log("form", form, this.$refs[form]); this.$refs[form].validate(valid => { this.$refs.upload.submit() }) }, // 导入关闭 daorucloseDialog() { this.daorudialogFormVisible = false }, // 导入之前 beforeUploadFile(file) { console.log('上传之前', file) console.log('daoru', this.daoru) const isLt10M = file.size / 1024 / 1024 < 10 const isText = file.type === 'application/vnd.ms-excel' const isTextComputer = file.type === 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' if (!isLt10M) { this.$message.error('上传文件大小不能超过10MB!') return false } if (!isText && !isTextComputer) { this.$message.error('上传文件类型必须为excel!') return false } }, // 导入成功 handleSuccess: function(res, file, fileList) { console.log('成功', res, file, fileList) const _this = this console.log(res) if (res.success === true) { _this.$alert('上传成功', '提示', { confirmButtonText: '确定', callback: action => { this.currentPage = 1 this._reportList() this.daorudialogFormVisible = false } }) } else { _this.$alert('上传失败,请稍后再试', '提示', { confirmButtonText: '确定', callback: action => { this.daorudialogFormVisible = false this.fileArr = [] } }) } }, // 删除文件 handleRemove(file, fileList) { console.log('file删除', file, fileList) }, // 选中文件 handlePreview(file) { // this.fileArr = file; console.log('file选中', file) }, // 文件限制 onexceed(files, fileList) { this.$message({ message: '最多只能上传一个文件', type: 'error' }) console.log('files, fileList', files, fileList) }
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
2018-08-15 给zTree的treeNode添加class