index.vue
1.18 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
<template>
<el-upload :action="define.comUrl+url" :headers="{ Authorization: $store.getters.token}"
:on-success="handleSuccess" :before-upload="beforeUpload" :show-file-list="false"
class="upload-btn">
<el-button :type="buttonType" icon="el-icon-upload2" :loading="loading">{{buttonText}}
</el-button>
</el-upload>
</template>
<script>
export default {
name: 'NCC-uploadBtn',
data() {
return {
loading: false
}
},
props: {
url: {
type: String,
default: ""
},
buttonText: {
type: String,
default: '导入'
},
buttonType: {
type: String,
default: 'text'
}
},
methods: {
beforeUpload() {
this.loading = true
},
handleSuccess(res) {
this.loading = false
if (res.code == 200) {
this.$message({
message: res.msg,
type: 'success',
duration: 1000
})
this.$emit('on-success')
} else {
this.$message({
message: res.msg,
type: 'error',
duration: 1000
})
}
}
}
};
</script>
<style lang="scss" scoped>
.upload-btn {
display: inline-block;
margin: 0 10px;
}
</style>