<div class="upload-box clear">
<span class="fl">上传图片</span>
<div class="artistDet-logo-box fl">
<el-upload :action="this.baseServerUrl+'/fileUpload/uploadPic?filepath=artwork'" list-type="picture-card" :class="{disabled:uploadMainDisabled}"
:file-list="imagelist" :on-preview="handlePictureMainPreview" :on-remove="handleMainRemove" :on-success="handleMainSuccess" :beforeUpload="beforeAvatarUpload">
</el-upload>
<el-dialog :visible.sync="dialogMainVisible" >
<img width="100%" :src="dialogMainImageUrl" alt="">
</el-dialog>
</div>
</div>
beforeAvatarUpload(file) {
var testmsg=file.name.substring(file.name.lastIndexOf('.')+1)
const extension = testmsg === 'jpg'
const extension2 = testmsg === 'png'
const isLt2M = file.size / 1024 / 1024 < 10
if(!extension && !extension2) {
this.$message({
message: '上传文件只能是 jpg、png格式!',
type: 'warning'
});
}
if(!isLt2M) {
this.$message({
message: '上传文件大小不能超过 10MB!',
type: 'warning'
});
} return extension || extension2 && isLt2M
} ,
将beforeAvatarUpload加到methods里面
转载于:https://www.cnblogs.com/ymdzha/p/9224933.html