file-upload.vue
1.54 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
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
<template>
<Upload ref="upload"
:id="id"
:action="action"
:data="data"
:accept="accept"
:maxSize="maxSize"
:on-success="success"
:on-error="error"
:before-upload="beforeUpload">
<Button type="ghost" icon="ios-cloud-upload-outline">上传文件</Button>
</Upload>
</template>
<script>
import _ from 'lodash';
export default {
name: 'file-upload',
props: {
action: {
type: String,
default: '/Api/upload/image'
},
data: {
type: Object,
default: () => {
return {
bucket: 'goodsimg'
};
}
},
accept: {
type: String,
default: 'image/png,image/jpeg,image/gif,image/jpg'
},
maxSize: {
type: Number,
default: 512 * 1024
},
id: {
type: Object,
default: () => {
return {};
}
}
},
data() {
return {};
},
methods: {
success(response) {
let files = [];
if (_.get(response, 'data.imagesList.length', 0)) {
files = response.data.imagesList;
}
this.$emit('on-success', this.id, files);
},
error(error) {
this.$Message.error('上传失败');
this.$emit('on-error', this.id, error);
},
beforeUpload() {
this.$refs.upload.clearFiles();
return true;
}
}
};
</script>