element-ui upload组件上传


方法一:
<el-table-column label="操作">
<template slot-scope="scope">
<el-button icon="el-icon-circle-plus-outline" type="primary" v-on:click="addOp(scope.row)"></el-button>
<el-button type="primary" v-on:click="importQuato(scope.row)">导入额度批次表</el-button>
</template>
</el-table-column>
<el-button type="primary" v-on:click="importQuato(scope.row)">导入额度批次表</el-button>//导入按钮
scope.row可以获取每一列的id <el-dialog :title="title" :visible.sync="dialogVisible">
<el-upload
class="upload-demo"
drag
class='ensure ensureButt'
action="123" //这里可以随意不影响
:before-upload="beforeAvatarUpload" //上传前文件校验
multiple>
<i class="el-icon-upload"></i>
<div class="el-upload__text">将文件拖到此处,或<em>点击上传</em></div>
<div class="el-upload__tip" slot="tip">只能上传xls、xlsx文件,且不超过10MB</div>
</el-upload>
<div slot="footer" class="dialog-footer">
<!--<el-button v-on:click="dialogVisible = false">取 消</el-button>-->
<el-button type="primary" v-on:click="dialogVisible = false">确 定</el-button>
</div>
</el-dialog>
// 上传前对文件的大小的判断
beforeAvatarUpload (file) {
var fileName=new Array()
fileName =file.name.split('.');
const extension = fileName[fileName.length-1] === 'xls'
const extension2 = fileName[fileName.length-1]=== 'xlsx'
const isLt2M = file.size / 1024 / 1024 < 10
if (!extension && !extension2) {
this.$message({
message: '上传模板只能是xls、xlsx格式!',
type: 'warning'
});
// console.log('上传模板只能是xls、xlsx格式!')
}
if (!isLt2M) {
this.$message({
message: '上传模板大小不能超过 10MB!',
type: 'warning'
});
// console.log('上传模板大小不能超过 10MB!')
}
if (extension || extension2 && isLt2M == true) {
console.log(file)
let fd = new FormData()
fd.append('invoiceTypeId', this.invoice_type_id)//随文件上传的其他参数
fd.append('epid', this.epid)
fd.append('file', file)
// console.log(fd)
this.newImport(fd).then(function (res) {//校验完成后提交
console.log(res)
}, function () {
console.log('failed');
});
return true
}
return extension || extension2 && isLt2M
},
//提示信息
open: function (msg, code) {
if (code == '000') {
this.$alert(msg, '提示', {
confirmButtonText: '确定',
type: 'success',
callback: action => {
this.dialogFormVisible = false;
location.reload();
}
});
} else {
this.$alert(msg, '提示', {
confirmButtonText: '确定',
type: 'error',
callback: action => {
this.dialogFormVisible = false;
location.reload();
}
});
}
},
newImport (data) {
this.$http.post('../enterPriseQuota/importEnterPriseQuota', data).then(function (res) {//成功后回调
let code = res.data.returncode;//返回json结果
let msg = res.data.msg;
this.open(msg, code);
console.log('success');
}, function () {
console.log('failed');
});
},
}
@RequestMapping("/importEnterPriseQuota")
@ResponseBody
public Map importEnterPriseQuota(@RequestParam(value = "invoiceTypeId") String invoiceTypeId,
@RequestParam(value = "epid") String epid,
@RequestParam("file") MultipartFile proFile, HttpServletRequest request) {
String fileDir = request.getSession().getServletContext().getRealPath("/tmp");
File dir = new File(fileDir);
Map resMap = null;
File file = null;
try {
file = new File(fileDir, proFile.getOriginalFilename());
if (!dir.exists()) {
dir.mkdir();
}
if (!file.exists()) {
file.createNewFile();
}
proFile.transferTo(file);
Date a = new Date();
resMap = enterPriseQuotaService.importEnterPriseQuato(invoiceTypeId,file,epid);
Date b = new Date();
log.info("************all_time*************************" + (b.getTime() - a.getTime()));
return resMap;
} catch (IOException e) {
e.printStackTrace();
} finally {
if (file != null && file.exists()) {
file.delete();
}
}
resMap.put("returncode", "999");
resMap.put("msg", "程序异常,请联系管理员");
return resMap;
}
方法二:
<el-dialog :title="tagName" :visible.sync="dialogVisible">
<el-upload
class="upload-demo"
drag
class='ensure ensureButt'
:action="importFileUrl"//在初始时指定url地址即可
:on-error="uploadError"
:on-success="uploadSuccess"
:before-upload="beforeAvatarUpload"
multiple>
<i class="el-icon-upload"></i>
<div class="el-upload__text">将文件拖到此处,或<em>点击上传</em></div>
<div class="el-upload__tip" slot="tip">只能上传xls、xlsx文件,且不超过10MB</div>
</el-upload>
<div slot="footer" class="dialog-footer">
<!--<el-button v-on:click="dialogVisible = false">取 消</el-button>-->
<el-button type="primary" v-on:click="dialogVisible = false">确 定</el-button>
</div>
</el-dialog>
//有时候 :on-success,:on-error 这个函数会无法调用,之前看另一个帖子是用的:onError="uploadError" :onSuccess="uploadSuccess"
http://blog.csdn.net/qq_39685062/article/details/77036582
2018-01-12: 昨天又遇到上传成功但是无法调用成功回调函数的问题,这里涉及到vue的生命周期,导致无法调用,js也不会报错,把对应函数放到methods顶部可解决。
// 上传成功后的回调
uploadSuccess (response) {
let code = response.returncode;
let msg = response.msg;
this.open(msg, code);
},
// 上传错误
uploadError (response) {
this.open("500", "文件导入异常!");
},
@RequestMapping("inEmployee")
@ResponseBody
public Map inEmployee(HttpServletRequest servletRequest) {
MultipartHttpServletRequest request = (MultipartHttpServletRequest) servletRequest;
Iterator<String> itr = request.getFileNames();
MultipartFile proFile = null;
while (itr.hasNext()) {
String str = itr.next();
proFile = request.getFile(str);
}
String fileDir = request.getSession().getServletContext().getRealPath("/tmp");
File dir = new File(fileDir);
Map resMap = null;
File file = null;
try {
file = new File(fileDir, proFile.getOriginalFilename());
if (!dir.exists()) {
dir.mkdir();
}
if (!file.exists()) {
file.createNewFile();
}
proFile.transferTo(file);
Date a = new Date();
resMap = employeeService.insEm(file,fileDir);
Date b = new Date();
log.info("************all_time*************************" + (b.getTime() - a.getTime()));
return resMap;
} catch (IOException e) {
e.printStackTrace();
} finally {
if (file != null && file.exists()) {
file.delete();
}
}
resMap.put("returncode", "999");
resMap.put("msg", "程序异常,请联系管理员");
return resMap;
}
element-ui upload组件上传的更多相关文章
- React antd如何实现<Upload>组件上传附件再次上传已清除附件缓存问题。
最近在公司做React+antd的项目,遇到一个上传组件的问题,即上传附件成功后,文件展示处仍然还有之前上传附件的缓存信息,需要解决的问题是,要把上一次上传的附件缓存在上传成功或者取消后,可以进行清除 ...
- vue watch 监听element upload组件上传成功返回的url列表
因为 on-success 上传成功返回的是一个异步的结果....如果父组件需要这个结果的话 必须用watch 监听 然后里面建立一个 save()方法 save方法里面再调用接口 传需要的上传之后的 ...
- element ui实现手动上传文件,且只能上传单个文件,并能覆盖上传。
element ui提供了成熟的组件场景,但实际工作中难免会遇到认(sha)真(diao)的产品.比如,最近遇到的,要求实现手动上传特定格式文件(用户点击“上传文件”按钮,确定之后,只是单纯选择了文件 ...
- Vue+Element UI 实现视频上传
一.前言 项目中需要提供一个视频介绍,使用户能够快速.方便的了解如何使用产品以及注意事项. 前台使用Vue+Element UI中的el-upload组件实现视频上传及进度条展示,后台提供视频上传AP ...
- Ant Design Upload 组件上传文件到云服务器 - 七牛云、腾讯云和阿里云的分别实现
在前端项目中经常遇到上传文件的需求,ant design 作为 react 的前端框架,提供的 upload 组件为上传文件提供了很大的方便,官方提供的各种形式的上传基本上可以覆盖大多数的场景,但是对 ...
- Element UI中的上传文件功能
上传文件给后台: <el-upload style="display:inline-block" :limit=" class="upload-demo& ...
- VUE -- iview table 组件 中使用 upload组件 上传组件 on render 事件不会触发问题
碰到的问题是: upload 组件在 on中写的监听事件不会被触发 在 props 中来监听:==>
- 关于本地使用antd的upload组件上传文件,ngnix报错405的问题
使用阿里的ui框架antd的upload,会自动请求ngnix上面的一个路径,也就是action所在的位置,一直报错405 not allowed,后来经讨论,统一将action写成一个路径,后端对这 ...
- 使用element的upload组件实现一个完整的文件上传功能(上)
说到标题就有点心塞了,前段时间项目上需要实现一个文件上传的功能,然后就咔咔的去用了element的upload组件,不用不知道一用吓一跳哇. 在使用的过程中遇到了很多让意想不到的问题,后来也因为时间问 ...
随机推荐
- bootstrap栅格系统中同行div高度不一致的解决方法
通过div底部的margin和padding实现,缺点:下边框无法完整显示,建议在无边框情况下使用 .row{ overflow: hidden; } [class*="col-" ...
- Codeforces 938G Shortest Path Queries [分治,线性基,并查集]
洛谷 Codeforces 分治的题目,或者说分治的思想,是非常灵活多变的. 所以对我这种智商低的选手特别不友好 脑子不好使怎么办?多做题吧-- 前置知识 线性基是你必须会的,不然这题不可做. 推荐再 ...
- 洛谷P4451 [国家集训队]整数的lqp拆分 [生成函数]
传送门 题意简述:语文不好不会写,自己看吧 思路如此精妙,代码如此简洁,实是锻炼思维水经验之好题 这种题当然是一眼DP啦. 设\(dp_n\)为把\(n\)拆分后的答案.为了方便我们设\(dp_0=1 ...
- Oracle Database 11g : SQL 基础
简介 1:课程目标 2:课程 目标 3:Oracle Database 11g 以及相关产品概览 1:Oracle Database 11g :重点领域 2:Oracle Fusion Middlew ...
- Maven设置本地仓库路径
在maven文件下的settings.xml中添加<localRepository>F:\cppdy\repo</localRepository>(本地仓库路径)
- LeetCode(78):子集
Medium! 题目描述: 给定一组不含重复元素的整数数组 nums,返回该数组所有可能的子集(幂集). 说明:解集不能包含重复的子集. 示例: 输入: nums = [1,2,3] 输出: [ [3 ...
- GIT的基本使用及应用场景
一.什么是GIT? Git 是一个开源的分布式版本控制软件,用以有效.高速的处理从很小到非常大的项目版本管理. GitHub.GitCafe.BitBucket和GitLab等是基于Git版本控制的远 ...
- Niagara workbench 介绍文档---翻译
一. 发现在建立station的时候存在一些问题,所以对技术文档部分做一个详细的了解,在这之前对出现的问题总结一下 1. 在 Windows操作系统中Application Direction中可以 ...
- Nginx详解一:Nginx基础篇之环境准备
环境确认: 1.确认系统网络可用 2.确认yum源可用 3.确认关闭iptabkes规则 查看是否有iptabkes规则:iptables -L 如果有的话:iptables -F关闭 保险起见也看看 ...
- linux添加自定义命令
想添加一个命令, 比如我输入 cdms 按回车, 然后就执行了: cd /mnt/gopath/src/test/app/ 这条命令方法: vi /etc/bashrc 在文件末尾添加 alias c ...
