vue-element:文件上传七牛之key和异步的问题
效果图:


html 代码:
<el-form-item label="Excel文件" :label-width="formLabelWidth" prop="excelurl">
<el-upload class="avatar-uploader"
ref="upload"
action="//up.qbox.me/"
:auto-upload="false"
:show-file-list="false"
:on-success="handleFileSuccess"
:on-error="handleFileError"
:on-change="handleChange"
:before-upload="beforeFileUpload"
:data="uploadFile">
<el-button slot="trigger" size="small" type="primary" class="file-select-btn">选择文件</el-button>
<el-button class="upload-file-btn" size="small" type="primary" :disabled="isSuccessUpload" @click="uploadAction">上传</el-button>
</el-upload>
<el-input type="text" v-model="form.excelurl" class="upload-file-input" v-if="fileState" disabled></el-input>
<el-button size="small" type="primary" class="change-file-btn" v-if="btnState" @click="fileState=false;btnState=false">修改</el-button>
</el-form-item>
其中: auto-upload="false" 为选择文件后不立即上传 on-change="handleChange" 为状态改变立即触发
Js代码:
beforeFileUpload(file) {
let filetype = file.name.slice(file.name.lastIndexOf('.'),file.name.length)
if (filetype === '.xls' || filetype === '.xlsx') {
// return true
} else {
this.$message.error('请上传EXCEL格式文件')
return false
}
const isLt2M = file.size / 1024 / 1024 < 2
if (!isLt2M) {
this.$message.error('上传文件大小不能超过 2MB!')
return false;
}
},
handleChange(file){
if(!this.fileState){
this.$http.post(GET_UPLOAD_TOKEN, {}).then(res => {
if (res.data.ret === 0) {
this.uploadFile = {key:file.name,token : res.data.data.upToken}
this.form.excelurl = file.name
this.fileState = true
}else{
return false
}
})
}
},
uploadAction(){
this.$refs.upload.submit()
},
上传成功:

vue-element:文件上传七牛之key和异步的问题的更多相关文章
- vue + element 文件上传 并将文件转 base64
当时有一个需求 是需要用到上传文件这个功能,并且需要将文件转为 base64 给到后台.网上找的全是啥图片转base64 肯定是因为这类需求比较常见.当时有点懵了.后面一想,都他娘是文件啊.然后就找到 ...
- nodejs+phantomjs+七牛 实现截屏操作并上传七牛存储
近来研究了下phantomjs,只是初涉,还谈不上深入研究,首先介绍下什么是phantomjs. 官网上的介绍是:”PhantomJS is a headless WebKit scriptable ...
- springboot+vue实现文件上传
https://blog.csdn.net/mqingo/article/details/84869841 技术: 后端:springboot 前端框架:vue 数据库:mysql pom.xml: ...
- php base64编码图片上传七牛
上网上找了好几个例子 都是自己写curl上传 感觉七牛这么多年了不应该sdk不提供一个方法 然后试 试 试 显示put 方式 上传上去 就是个字符串 后来换成文件上传方法 putFile 成了 不废话 ...
- vue element-ui 文件上传
<el-upload class="upload-demo" action="" :before-remove="beforeRemove&qu ...
- vue+springboot文件上传
//vue element-ui组件 <el-upload style="position: relative;top: -40px;left: 240px;" ...
- vue element upload上传、清除等
如果项目中可以使用file-list,那我们可以点击file-list删除文件列表: 有时候项目中是不要这个文件列表的,所以在上传成功以后,文件列表一直存在,要重新上传就必须刷新页面,所以我们需要手动 ...
- vue大文件上传控件选哪个好?
需求: 项目要支持大文件上传功能,经过讨论,初步将文件上传大小控制在20G内,因此自己需要在项目中进行文件上传部分的调整和配置,自己将大小都以20G来进行限制. PC端全平台支持,要求支持Window ...
- vue大文件上传插件选哪个好?
文件夹数据库处理逻辑 public class DbFolder { JSONObject root; public DbFolder() { this.root = new JSONObject() ...
随机推荐
- STM32通过调用库函数进行编程
1.调用库函数编程和直接配置寄存器编程的差别: 2.CMSIS标准: 3.STM32库函数的组织: 4.程序例举: 调用库函数实现通过USART发送数据(26个大写的英文字母) 首先:在主函数部分先要 ...
- IO获取指定目录及其目录下子目录
一.需求:获取指定目录下,指定扩展名的文件(包含子目录中的) 二.需要用到的方法 1.FilenameFilter :返回抽象路径名的定义中表示此抽象路径名的目录中的文件的数组. filter.ac ...
- IDEA debug调式快捷键
F9 resume programe 恢复程序 Alt+F10 show execution point 显示执行断点 F8 Step Over 相当于eclipse的f6 跳到下一步 F7 Step ...
- 设计模式-(15)责任链模式 (swift版)
一,概念: 责任链模式(Chain of Responsibility Pattern)为请求创建了一个接收者对象的链.这种模式给予请求的类型,对请求的发送者和接收者进行解耦.这种类型的设计模式属于行 ...
- java 内存简介
java程序对内存分配的方式一般有三种: (1) 从静态存储区域分配.内存在程序编译的时候就已经分配好,这块内存在程序的整个运行期间都存在.例如全局变量. (2) 在栈上创建. 在执行函数时,函数内局 ...
- Android 网络调试 adb tcpip 开启方法
查看ip地址:adb shell ifconfig 1.连接USB数据线,打开usb调试,使用windows的“运行”命令行方式:(此方法需配置adb环境变量,也可直接进入adb工具目录执行\andr ...
- python利用决策树进行特征选择
python利用决策树进行特征选择(注释部分为绘图功能),最后输出特征排序: import numpy as np import tflearn from tflearn.layers.core im ...
- Android JNI MAC OS环境配置
前言—JNI技术简介 JNI是Java Native Interface的缩写,即“Java本地调用”,它是Java世界和Native世界的中介桥梁.其中Native世界一般指C/C++的世界.众所周 ...
- zoj 3471(状态压缩DP,类似于点集配对)
Most Powerful Time Limit: 2 Seconds Memory Limit: 65536 KB Recently, researchers on Mars have d ...
- AWS EC2中部署Apache服务器(LAMP)
关键词: 1.新建aws ec2实例 2.使用putty连接到aws ec2 实例(SSH协议) 3.使用filezilla连接到aws ec2实例(SFTP协议) 4.在aws ec2上部署apac ...