图片文件换汤不换药,只要注意前端的写法即可

1.饿了么组件可以利用 http-request 的属性对上传进行自定义 :http-request="uploadFile"

2.设置文件FormData对象传入请求

const formdata = new FormData();
const file = params.file;
formdata.append("file", file);

3.全部代码

<template>
<div style="margin-top:5%">
<el-upload
:onError="uploadError"
:onSuccess="uploadSuccess"
class="upload-demo"
ref="upload"
:auto-upload="false"
accept=".eml"
multiple
:before-upload="beforeUpload"
action=" "
:http-request="uploadFile"
>
<el-button slot="trigger" size="small" type="primary">----</el-button>
<el-button slot="trigger" size="small" type="primary">----</el-button>
<el-button slot="trigger" size="small" type="primary">----</el-button>
<el-button slot="trigger" size="small" type="primary">----</el-button>
<el-button slot="trigger" size="small" type="primary">选取邮件</el-button> <el-button style="margin-left: 10px;" size="small" type="success" @click="submitUpload">上传邮件</el-button>
<div slot="tip" class="el-upload__tip">可以同时上传多个eml文件至服务器</div>
</el-upload>
</div>
</template>
<script>
import axios from "axios";
export default {
data() {
return {};
},
computed: {
//进入的用户
userSO_json() {
let userSO_json = JSON.parse(sessionStorage.getItem("userSO_json"));
return userSO_json;
}
},
methods: {
/**
* 自定义:http-request="uploadFile"之后,回调方法暂且失效,所以提示信息应该写在axios里面
*/
// 上传成功后的回调
uploadSuccess(response, file, fileList) {
console.log("上传文件", response);
this.$message({
showClose: true,
message: "恭喜你,邮件上传成功",
type: "success"
});
},
// 上传错误后的回调
uploadError(err, file, fileList) {
if (err.message != "") {
this.$message.warning(err.message);
} else {
this.$message.warning("网络错误,不能访问");
}
},
uploadFile(params) {
const formdata = new FormData();
const file = params.file;
formdata.append("file", file);
axios
.post("/api/EmlUploadController/uploadFile?userName="+this.userSO_json.userName, formdata, {
headers: {
//头部信息
"Content-Type": "multipart/form-data",
token: this.userSO_json.token
}
})
.then(response => {
this.$message({
showClose: true,
message: "恭喜你,邮件上传成功",
type: "success"
});
})
.catch(error => {
//前端的token留在点击退出按钮那里删除,这里就只是提示过期
if (error.message != "") {
this.$message.warning("此封一模一样邮件你已经上传过了");
} else {
this.$message.warning("后端token过期,请重新登录");
}
});
},
//添加任务
async beforeUpload(file) {
console.log("beforeUpload");
// const extension = file.name.split(".")[1] === "eml";
// const isLt2M = file.size / 1024 / 1024 < 10;
// if (!extension) {
// console.log("上传邮件只能是 eml格式!");
// }
// if (!isLt2M) {
// console.log("上传邮件大小不能超过 10MB!");
// }
// return extension && isLt2M;
}, //提交
submitUpload() {
this.$refs.upload.submit();
}
}
};
</script>
<style scoped>
.el-table--border,
.el-table--group {
border: none;
}
.el-table__header-wrapper th:nth-last-of-type(2) {
border-right: none;
}
.el-table--border td:nth-last-of-type(1) {
border-right: none;
}
.el-table--border::after,
.el-table--group::after {
width: 0;
}
.el-select .el-input {
width: 180px;
}
.input-with-select .el-input-group__prepend {
background-color: #fff;
}
.input-with-select {
margin-left: -5px;
}
.select {
margin-left: 0px;
}
.input-with-select {
background-color: #fff;
width: 390px;
}
.pagination {
height: 80px;
text-align: center;
}
.choose {
float: left;
}
.upload-demo {
float: left;
}
.button1 {
left: 40%;
}
.button2 {
text-align: center;
}
.divider {
margin: 0;
}
.conditionalQuery {
float: right;
height: 60px;
margin-right: 80px;
}
</style>

饿了么Element UI之Upload组件图片上传【原创】的更多相关文章

  1. vue问题三:element ui的upload组件上传图片成功和移除事件

    element ui的upload组件上传图片成功和移除事件: 登录后获取到后台传的token存到中: sessionStorage.setItem("token",data.ob ...

  2. 前端element ui 文件base64加密字符串 上传

    <el-form-item label="附件" prop="attachment"> <el-upload :multiple=" ...

  3. UI组件--element-ui--Upload多组件自定义上传

    需求: 提交详细信息的表单, 并上传对应图片(如下图), 后台接口要求表单数据和图片需要一次上传完成.. 分析: 实际上, 每个element-ui Upload组件都应发送一次请求, 很明显不符合我 ...

  4. antd组件Upload实现自己上传

    前言 在实现图片上传时,可能需要用到Upload,但是它默认的上传方式是加入图片后直接上传,如果要实现最后再一次性上传,需要自定义内容. //添加按钮的样式 const uploadButton = ...

  5. 06.LoT.UI 前后台通用框架分解系列之——浮夸的图片上传

    LOT.UI分解系列汇总:http://www.cnblogs.com/dunitian/p/4822808.html#lotui LoT.UI开源地址如下:https://github.com/du ...

  6. Jquery图片上传组件,支持多文件上传

    Jquery图片上传组件,支持多文件上传http://www.jq22.com/jquery-info230jQuery File Upload 是一个Jquery图片上传组件,支持多文件上传.取消. ...

  7. vue图片上传组件

    前言:很多项目中都需要用到图片上传功能,而其多处使用的要求,为了避免重复造轮子,让我决定花费一些时间去深入了解,最终封装了一个vue的图片上传组件.现将总结再次,希望有帮助. Layout <d ...

  8. 图片上传组件webuploader

    前端组件webuploader 当时也是搞了很久参考这种demo,但是没记.现在事后大致总结下.直接上大概代码(我使用asp.net  MVC来做的): 执行顺序:(get)Record/Add——A ...

  9. 图片上传--Upload

    图片上传--Upload 图片上传基于spring框架写的代码: 1.首先:我们要再springmvc中添加试图解析器: <!-- 图片解析器 --> <bean id=" ...

  10. MVC文件上传05-使用客户端jQuery-File-Upload插件和服务端Backload组件自定义上传文件夹

    在零配置情况下,文件的上传文件夹是根目录下的Files文件夹,如何自定义文件的上传文件夹呢? MVC文件上传相关兄弟篇: MVC文件上传01-使用jquery异步上传并客户端验证类型和大小  MVC文 ...

随机推荐

  1. 洛谷P1209修理牛棚 Barn Repair

    [USACO1.3] 修理牛棚 Barn Repair 题目描述 在一个月黑风高的暴风雨夜,Farmer John 的牛棚的屋顶.门被吹飞了 好在许多牛正在度假,所以牛棚没有住满. 牛棚一个紧挨着另一 ...

  2. jQuery的基本操作总结

    什么是jquery? 就是一个用js的插件库   解决了原生dom的操作的兼容性和代码量 使用前需要引入它的js库 以下例子以 jQuery1.12.4.js  这个版本为例 一:jQuery入口函数 ...

  3. Linux下简单几步安装AI开发环境-ROS(超有意思)

    机缘巧合,接触到了一个开源的项目ROS,只需要根据一口君的操作,就可以很容易搭建一个具有3d效果的开发环境,非常有意思,和大家分享下. 0.什么是ROS ROS(Robot Operating Sys ...

  4. SLAB:华为开源,通过线性注意力和PRepBN提升Transformer效率 | ICML 2024

    论文提出了包括渐进重参数化批归一化和简化线性注意力在内的新策略,以获取高效的Transformer架构.在训练过程中逐步将LayerNorm替换为重参数化批归一化,以实现无损准确率,同时在推理阶段利用 ...

  5. cdh6.3.2 hue集成hbase

    参考地址:https://blog.csdn.net/u010886217/article/details/98606976

  6. 题解:SP22382 ETFD - Euler Totient Function Depth

    题目链接: link,点击这里喵. 前置知识: [模板]线性筛素数,欧拉函数,点击这里喵. 题意简述: 给定整数 $l,r,k$,求出 $[l,r]$ 中有多少个整数不断对自己取欧拉函数刚好 $k$ ...

  7. Go channel 介绍

    Go 语言(Golang)中的 chan 是通道(channel)的缩写,用于在不同的 goroutine 之间进行通信.通道允许你在 goroutine 之间传递数据,从而实现同步和共享内存.下面是 ...

  8. Kubernetes-3.2:kubespray安装高可用k8sv1.20.2集群及常见报错解决

    kubespray安装高可用k8s集群 环境介绍 系统环境 主机名 / IP地址 角色 内核版本 CentOS 7.6.1810 master1 / 192.168.181.252 master &a ...

  9. sicp每日一题[1.41]

    Exercise 1.41 Define a procedure double that takes a procedure of one argument as argument and retur ...

  10. sql转JSON为表

    创建方法 : /****** Object: UserDefinedFunction [dbo].[parseJSON] Script Date: 2017/7/11 18:27:28 ******/ ...