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
| <template>
| <div>
| <el-upload
| ref="upload"
| action="#"
| :before-upload="beforeUpload"
| :http-request="uploadFile"
| :file-list="fileList"
| :on-success="uploadFileSuccess"
| accept=".xls, .xlsx"
| :limit="1"
| :auto-upload="true"
| :show-file-list="false"
| >
| <el-button size="small" type="primary">导入</el-button>
| </el-upload>
| </div>
| </template>
| <script>
| import { yearPlanDetailImport } from '../../../../../assets/api/api';
| export default {
| data() {
| return {
| fileList: []
| }
| },
| methods: {
| /**
| * @desc 上传文件
| */
| beforeUpload(file) {
| this.fileList = [file]
| },
| /**
| * @desc 上传至服务器
| */
| async uploadFile() {
| console.log('文件', this.fileList[0])
| let formData = new FormData()
| formData.append('file', this.fileList[0])
| const { code, data } = await this.$axios({
| method: 'post',
| url: yearPlanDetailImport,
| data: formData,
| headers: {
| 'Content-Type': 'multipart/form-data;'
| },
| noQs: true
| })
| if(code == 200) {
| this.$emit('upload')
| }
| },
| uploadFileSuccess() {
| this.$refs.upload.clearFiles()
| }
| }
| }
| </script>
|
|