一、 图片上传
其实 EleUI 有现成的 上传图片 / 头像 ,自己用还是要改一下。
<el-upload class="avatar-uploader" action="uploadData" :http-request="UploadImage"
:show-file-list="false" :on-success="handleAvatarSuccess" :before-upload="beforeAvatarUpload">
<img v-if="imageUrl" :src="addimg" style="width: 100px;height: 100px;">
<i v-else class="el-icon-plus avatar-uploader-icon"></i>
</el-upload>
handleAvatarSuccess(res, file) {
this.imageUrl = URL.createObjectURL(file.raw);
},
beforeAvatarUpload(file) {
const isJPG = file.type == 'image/jpeg';
const isLt2M = file.size / 1024 / 1024