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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
<template>
<div>
<el-upload
accept=".jpg,.jpeg,.png,.JPG,.JPEG,.PBG"
:class="{disabled:uploadDisabled}"
action="http://111.203.232.175:8088/mall/file/image/upload"
list-type="picture-card"
:on-preview="handlePictureCardPreview"
:on-remove="handleRemove"
:on-success="handleAvatarSuccess"
:headers="headers"
:file-list="fileList"
:limit="1"
:multiple ="false"
>
<i class="el-icon-plus"></i>
<div slot="tip" class="el-upload__tip color_red">只能上传.jpg/.jpeg/.png文件</div>
</el-upload>
<el-dialog :visible.sync="dialogVisible">
<img width="100%" :src="dialogImageUrl" alt />
</el-dialog>
</div>
</template>
<script>
export default {
props:{
fileList:{
type:Array,
default:[
{
name: "",
url: "",
},
]
},
},
data() {
return {
dialogImageUrl: "",
dialogVisible: false,
imageUrl:""
};
},
computed: {
headers() {
// return { 'token': this.backToken }
return {'Authorization':localStorage.getItem('backToken')}
},
uploadDisabled:function() {
return this.imageUrl !== ''
},
},
methods: {
// 图片上传成功的返回值
handleAvatarSuccess(res, file) {
// this.$emit('qrcodeUrl', res.data.url)
if (res.resultCode == 200) {
this.$emit('qrcodeUrl', res.data.url)
this.imageUrl = res.data.url;
} else {
this.$message.error(res.message);
}
},
handleRemove(file, fileList) {
console.log(file, fileList);
this.$emit("qrcodeUrl", "");
this.imageUrl=""
},
handlePictureCardPreview(file) {
this.dialogImageUrl = file.url;
this.dialogVisible = true;
}
}
};
</script>
<style>
.color_red{
color:red;
}
.disabled .el-upload--picture-card {
display: none;
}
</style>