<el-upload class="upload-demo" action=" 这里你是要导入的接口地址( 不是所有文件上传的地址,是单独导入的地址 ) " :on-success="handleAvatarSuccess" :before-upload="beforeAvatarUpload" :limit="1" :file-list="fileList" > <el-button size="small" type="primary">点击上传</el-button> <div slot="tip" class="el-upload__tip">仅支持ExcelO3,既xls格式</div> </el-upload>
data 建立对象
fileList : [], // 这是为了方便上传之后清空数据展示
methods 方法
//上传成功的样子 handleAvatarSuccess(res, file) { if(res.code == '500') { this.$message.error(res.msg) this.fileList = [] return } this.fileList = [] this.$message.success("导入成功") }, beforeAvatarUpload(file){ var testmsg = file.name.substring(file.name.lastIndexOf('.')+1) const xls = testmsg === 'xls' const xlsx = testmsg === 'xlsx' if(!xls && !xlsx ){ this.$message.error("请选择xls/xlsx 格式的文件") return false } return xls || xlsx },