实现文件的选择,判定
首先是upload模板
<el-upload
ref="upload"
:limit="1"
:before-upload="beforeUpload"
:auto-upload="false"
:headers="headers"
:on-success="handleSuccess"
:on-error="handleError"
accept=".xlsx, .xls"
:action="fileUploadApi + '?name=' + name" >
<div class="title">请上传需要导入分配的设备实例数据</div>
</el-upload>
需要在data中定义neme
name: "",
然后是调用方法
methods: {
// 上传文件,点击事件
upload() {
this.$refs.upload.submit();
},
beforeUpload(file) {
console.log(file);
let isLt2M = true;
isLt2M = file.size / 1024 / 1024 < 100;
//判断类型
if (!this.i