html
<input ref="fileinput" type="file" style="position:absolute; clip:rect(0 0 0 0);" accept="image/png, image/jpeg, image/gif, image/jpg" @change="uploadImg($event)">
js
uploadImg (e) {
const file = e.target.files[0];
this.fileType = file.type
if (!['image/png', 'image/jpg', 'image/gif', 'image/jpeg'].includes(this.fileType)) {
this.$Message.error('请上传正确的图片')
return
}
if (file.size > 20 * 1024 * 1024) {
this.$Message.error('请选择20M以内的图片')
return
}
if (typeof FileReader === 'function') {
const reader = new FileReader();
reader.readAsDataURL(file);
reader.onload = (event) => {
var Base64Val = event.target.result;
console.log( Base64Val)
}
} else {
alert('对不起,您的浏览器暂不支持此功能!');
}
}