forked from vincentzyc/form-design
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimg-upload.vue
More file actions
45 lines (44 loc) · 1.08 KB
/
img-upload.vue
File metadata and controls
45 lines (44 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<template>
<el-upload
class="avatar-uploader"
action="https://jsonplaceholder.typicode.com/posts/"
:show-file-list="false"
:on-success="handleAvatarSuccess"
:before-upload="beforeAvatarUpload"
:on-error="uploadError"
>
<img v-if="value" :src="value" class="avatar">
<i v-else class="el-icon-plus avatar-uploader-icon"></i>
</el-upload>
</template>
<script>
export default {
name: "ImgUpload",
props: {
value: String
},
methods: {
/* eslint-disable */
handleAvatarSuccess(res, file) {
this.$emit('update:value', URL.createObjectURL(file.raw))
this.fullLoading.close()
},
uploadError(err) {
console.log(err);
this.fullLoading.close();
this.$alert('网络繁忙,请稍后重试')
},
beforeAvatarUpload(file) {
const isLt2M = file.size / 1024 < 20;
if (!isLt2M) {
this.$message.error('上传图片大小不能超过 20 KB!');
} else {
this.fullLoading = this.$loading({
text: '正在上传'
});
}
return isLt2M;
},
}
}
</script>