vue限制文件上传大小和上传格式 - I_Dreamer
<el-form-item label="图片:" prop="tempImagePath"><el-upload
class="upload"
accept="image/jpeg"
:show-file-list="false"
list-type="picture-card"
:headers="{ token: token}"
:action="actionUrl"
:before-upload="beforeAvatarUpload"
:on-success="handleAvatarSuccess">
<img v-if="temp.tempImagePath"
:src="temp.tempImagePath" width="146px" height="146px"/>
<i v-else class="el-icon-plus"></i>
<div slot="tip" class="el-upload__tip">
只能上传.gif/.jpeg/.png文件且小于500K
</div>
</el-upload>
</el-form-item>
beforeAvatarUpload (file) {const imgType = file.type === \'image/jpeg\' || file.type === \'image/png\'
const isLt500k = file.size / 1024 / 1024 < 0.48;
if (!imgType) {
this.$message.error("上传图片只能是 JPG和png 格式!");
return false;
}
if (!isLt500k) {
this.$message.error("上传图片大小不能超过 500k!");
return false;
}
},
以上是 vue限制文件上传大小和上传格式 - I_Dreamer 的全部内容, 来源链接: utcz.com/z/379289.html