效果图:

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()
},

上传成功:

注:
    在上传七牛时通过给key赋值,上传了原本的文件名,不通过七牛随机产生
     通过on-change函数在选择文件后,请求到token, 然后再上传文件 

vue-element:文件上传七牛之key和异步的问题的更多相关文章

  1. vue + element 文件上传 并将文件转 base64

    当时有一个需求 是需要用到上传文件这个功能,并且需要将文件转为 base64 给到后台.网上找的全是啥图片转base64 肯定是因为这类需求比较常见.当时有点懵了.后面一想,都他娘是文件啊.然后就找到 ...

  2. nodejs+phantomjs+七牛 实现截屏操作并上传七牛存储

    近来研究了下phantomjs,只是初涉,还谈不上深入研究,首先介绍下什么是phantomjs. 官网上的介绍是:”PhantomJS is a headless WebKit scriptable ...

  3. springboot+vue实现文件上传

    https://blog.csdn.net/mqingo/article/details/84869841 技术: 后端:springboot 前端框架:vue 数据库:mysql pom.xml: ...

  4. php base64编码图片上传七牛

    上网上找了好几个例子 都是自己写curl上传 感觉七牛这么多年了不应该sdk不提供一个方法 然后试 试 试 显示put 方式 上传上去 就是个字符串 后来换成文件上传方法 putFile 成了 不废话 ...

  5. vue element-ui 文件上传

    <el-upload class="upload-demo" action="" :before-remove="beforeRemove&qu ...

  6. vue+springboot文件上传

    //vue element-ui组件 <el-upload style="position: relative;top: -40px;left: 240px;"        ...

  7. vue element upload上传、清除等

    如果项目中可以使用file-list,那我们可以点击file-list删除文件列表: 有时候项目中是不要这个文件列表的,所以在上传成功以后,文件列表一直存在,要重新上传就必须刷新页面,所以我们需要手动 ...

  8. vue大文件上传控件选哪个好?

    需求: 项目要支持大文件上传功能,经过讨论,初步将文件上传大小控制在20G内,因此自己需要在项目中进行文件上传部分的调整和配置,自己将大小都以20G来进行限制. PC端全平台支持,要求支持Window ...

  9. vue大文件上传插件选哪个好?

    文件夹数据库处理逻辑 public class DbFolder { JSONObject root; public DbFolder() { this.root = new JSONObject() ...

随机推荐

  1. Flex+Java+Blazeds

    1.环境:jdk1.6,Flex4.6 2.工具:MyEclipse10 3.server:Tomcat7 4.连接方式:Blazeds 5.项目类型:Flex项目 6.步骤 (1)新建Flex项目一 ...

  2. Response.ContentLength获取文件大小

    Response.ContentLength返回的是请求内容的大小,而不是请求文件的大小,当我们用Http断点续传的时候,比如文件大小为100M,第一次下载的时候ContentLength的大小就是1 ...

  3. ubuntu查看文件的权限

    查看linux文件的权限: 查看path路径下名为filename的文件或文件夹的权限: ls -l path/filename ls -l path/filename 查看path路径下的所有文件的 ...

  4. Lightoj 1006 Hex-a-bonacci

    Given a code (not optimized), and necessary inputs, you have to find the output of the code for the ...

  5. spring各个jar作用

    spring.jar --->包含完整发布模块的单个jar,但是不包括mock.jar,aspects.jar,spring-porltet.jar,spring-hibernate2.jar ...

  6. VMware克隆虚拟机后网络配置

    修复克隆虚拟机文件 # vi /etc/udev/rules.d/70-persistent-net.rules # PCI device 0x8086:0x100f (e1000) SUBSYSTE ...

  7. linux 远程杀掉进程

    转自http://blog.csdn.net/tengdazhang770960436/article/details/53906263 第一步:获取进程号 pid=$(ssh root@$remot ...

  8. css 实现元素四角图片样式,元素的大小不定

    demo 效果 css body { margin:; } .popup p{ margin-bottom:20px; margin-left:200px; } .popup p span{ disp ...

  9. 《C-RNN-GAN: Continuous recurrent neural networks with adversarial training》论文笔记

    出处:arXiv: Artificial Intelligence, 2016(一年了还没中吗?) Motivation 使用GAN+RNN来处理continuous sequential data, ...

  10. nodejs--JWT 在前后端分离中的应用与实践

    nodejs--JWT 在前后端分离中的应用与实践 http://www.cnblogs.com/lidongyue/p/5269695.html