是
upload
we need to check file size and file type before user upload files, but before-upload prop works only when auto-upload prop is true. so we hope upload component has a new hook before user change file.like this:
in template:
<el-upload :before-change="onBeforeChange"><el-upload>
and in script:
onBeforeChange (file, fileList) {
const isLt2M = file.size / 1024 / 1024 < 2;
if (!isLt2M) this.$message.error('file can not greater than 2MB!');
return isLt2M;
}
when return false, element-ui should abort changing file.
Translation of this issue:
yes
Upload
We need to check file size and file type before user upload files, but before-upload prop works only when auto-upload prop is true. So we hope upload component has a new hook before user change file.
In template:
And in script:
OnBeforeChange (file, fileList){
Const isLt2M = file. size / 1024 / 1024 < 2;
If (! IsLt2M) this. $message. error ('file can not be greater than 2MB!');
Return isLt2M;
}
When return false, element-ui should abort change file.
you can do :
<el-upload :auto-upload="false" :on-change="onChange"><el-upload>
onChange(file, fileList) {
if (file.size > 1024 * 1024 * this.size) {
this.$message.error(`file can not be greater than ${this.size}MB!`)
fileList.pop()
}
}
@de1ck yes, I thought so before, but this function is hard to reuse with unknown size limit. :(
I realized that my expecting is hard to reuse too, damn
maybe upload needs a prop named limitSize or sth. else, LOL
@de1ck thanks
Most helpful comment
maybe upload needs a prop named
limitSizeor sth. else, LOL