<el-upload class="avatar-uploader" action="1" :show-file-list="false" accept="/xlsx" :before-upload="(file)=>{ return beforeAvatarUpload(file,null)}"> <el-button type="primary">点击上传</el-button> </el-upload>
beforeAvatarUpload(file,index) { //上传之前事件 let that = this; let type1 = file.name.split('.'); //获取文件后缀 let type2 = type1[type1.length - 1].toLowerCase(); let type ="xlsx,xls,csv,pdf", isType = type.indexOf(type2); if(isType < 0){ this.$message.error(`请上传xlsx,xls,csv,pdf格式的文件!,您的文件格式为 ${type2}`); return; } console.log(type2); let isLt2M = file.size / 1024 / 1024 < 5; if (!isLt2M) { this.$message.error('上传文件大小不能超过 5MB!'); return isLt2M; } let fd = new FormData(); fd.append("file",file); inputObj(fd).then(res=>{ if(res.data.resp_code == 200){ this.$message.success('上传成功!'); }else{ this.$message.error('上传失败!'); } }) },