file 上传

​由于最近使用vue+Element ui vue2.0中upload组件存在很多上传地址不可跨域,或者上传获取后台接口的时候出现不可预算的bug。

所以我还是选择用了最原始的写法:

File

用于文件上传。

但是这个文件上传存在的样式确实不是那么的好看:

修改样式:

.file {

position: fixed;

display: inline-block;

background: rgb(77,179,255);

border: 1px solid #99D3F5;

border-radius: 4px;

padding: 0 20px;

overflow: hidden;

color: white;

text-decoration: none;

text-indent: 0;

/* line-height: 20px; */

right: 200px;

}

.file input {

position: absolute;

font-size: 100px;

right: 0px;

top:0;

opacity: 0;

}

.file:hover {

background: #AADFFD;

border-color: #78C3F3;

color: #004974;

text-decoration: none;

}

文件上传的js代码:

uploadUp(event) {

var files = event.target.files, file;

if (files && files.length > 0) {

// 获取目前上传的文件

file = files[0];// 文件大小校验的动作

if(file.size > 1024 * 1024 * 2) {

alert('文件已超过2M!上传失败!');

}else{

//发送请求上传

this.$http

.post(“上传接口“

{ headers: { "Content-Type": "multipart/form-data" } }

)

.then(function(res) {

}

},

文件上传的html代码:


上传

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。