Created
July 31, 2018 08:56
-
-
Save binary4cat/e3f5409e535f9ebb1d7fd9bb3ef34ea9 to your computer and use it in GitHub Desktop.
element ui 上传组件判断文件类型
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 图片上传之前调用的事件 | |
*/ | |
beforeAvatarUpload(file) { | |
// 允许所有的图片类型 | |
const isJPG = file.type.indexOf("image/") > -1; | |
const isLt2M = file.size / 1024 / 1024 < 2; | |
if (!isJPG) { | |
this.$message.error("请上传图片文件!"); | |
} | |
if (!isLt2M) { | |
this.$message.error('上传头像图片大小不能超过 2MB!'); | |
} | |
return isJPG && isLt2M; | |
}, |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment