我是靠谱客的博主 热心水壶,这篇文章主要介绍element上传不提交,点击提交触发上传,现在分享给大家,希望可以做个参考。

上传Excel,点击立即导入在请上传

校验:1.文件大小 2.文件类型 3.上传数量

复制代码
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
// html <el-input v-model="(fileList[0] || {}).name" disabled /> <el-upload ref="upload" v-model="fileList" :file-list="fileList" :action="url" accept=".xls,.xlsx" :show-file-list="false" :limit="1" :auto-upload="false" :on-exceed="handleExceed" :on-change="(file, fileList) => {handleChange(file,fileList)}" :on-success="handleSuccess" > <el-button>选择文件</el-button> </el-upload> <el-button @click="handleSubmit">立即导入</el-button> // data data() { return { fileList: [], url: 'xxxxx', // 请求地址 uploadResponse: null, // 导入返回的结果 } }, // methods: { // 上传校验 handleChange(file, fileList) { var XLS = false // 判断是否是excel if(file.name.split('.')[1] === "xls" || file.name,split('.')[1] === "xlsx"){ XLS = true } else { XLS = false } const isLt5M = file.size / 1024 /1024 < 5 //判断文件是否超出5M if(!XLS) this.$message.error('上传文件只能是Excel格式') if(!isLt5M ) this.$message.error('文件大小超出5M') if(XLS && isLt5M ) this.fileList = fileList if(XLS && isLt5M && fileList.length > 1) { this.fileList = [fileList[fileList.length - 1]] } return XLS && isLt5M }, // 选择文件超过1条,校验 handleExceed(files, uploadFiles) { this.uploadResponse = null const file = files[0] this.$refs.upload.handleStart(file) }, // 提交验证 handleSubmit() { if(!this.fileList.length) { this.$message.error('请上传文件') return } this.$refs.upload.submit() }, // 上传成功回调 handleSuccess(res) { this.$refs.uplad.clearFiles() // 清除上传文件 this.uploadResponse = res if(this.uploadResponse.retCode === 0){ this.$message.success('上传成功') } }

最后

以上就是热心水壶最近收集整理的关于element上传不提交,点击提交触发上传的全部内容,更多相关element上传不提交内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(49)

评论列表共有 0 条评论

立即
投稿
返回
顶部