zoukankan      html  css  js  c++  java
  • Vue使用 Element 组件实现文件一次性批量上传

    Vue使用 Element 组件实现文件一次性批量上传

    HTML

    <el-upload class="upload-demo" ref="upload" action="https://jsonplaceholder.typicode.com/posts/" :file-list="fileList" :auto-upload="false" :headers="{token: $cookie.get('token')}" :multiple='true' :show-file-list='true' :on-change="handleChange" :on-remove="handleRemove">
       <el-button slot="trigger" size="small" type="primary" icon="el-icon-plus" plain>模板文件选择,已选择{{fileList.length}}个</el-button>
       <el-button style="margin-left: 15px;" size="small" type="success" @click="submitUpload" :disabled="fileList.length<=0" icon="el-icon-upload" plain>将选择文件上传服务器</el-button>
    </el-upload>
    

    JavaScript

    export default {
    	data() {
          return {
            fileList: [], // 上传文件列表
            uploading: false,  // 是否正在上传文件
          }
        },
        methods: {
          // 选择文件改变
          handleChange(files, fileList) {
            this.fileList = fileList
          },
          // 移除文件
          handleRemove(file, fileList) {
            this.fileList = fileList
          },
          // 上传文件
          submitUpload() {
            console.log('---> ', this.fileList)
            this.uploading = true
            setTimeout(() => {
              this.uploading = false
              this.fileList = []
              this.$message({
                message: '文件上传成功!',
                type: 'success'
              });
            }, 5000)
          },
       }
    }
    

    CSS

     .l-s {
        background-color: #fff;
        padding: 20px;
        padding-top: 1px;
      }
    
      .d-z {
        text-align: center;
        position: absolute;
        top: 0;
        bottom: 0;
        left: 0;
        right: 0;
        background-color: rgba(255, 255, 255, 0.5);
        z-index: 1000;
      }
    

    最终效果

    【版权声明】本博文著作权归作者所有,任何形式的转载都请联系作者获得授权并注明出处!
    【重要说明】本文为本菜鸟的学习记录,论点和观点仅代表个人不代表此技术的真理,目的是学习和可能成为向别人分享的经验,因此有错误会虚心接受改正,但不代表此时博文无误!
    【博客园地址】JayveeWong: http://www.cnblogs.com/wjw1014
    【CSDN地址】JayveeWong: https://blog.csdn.net/weixin_42776111
    【Gitee地址】Jayvee:https://gitee.com/wjw1014
    【GitHub地址】Jayvee:https://github.com/wjw1014
  • 相关阅读:
    Java中抽象类和接口的区别(abstract class VS interface)
    ECUST_Algorithm_2019_4
    ECUST_Algorithm_2019_3
    杂题
    ECUST_Algorithm_2019_2
    Magolor的数据结构作业
    ECUST_Algorithm_2019_1
    atcoder 泛做
    2018中国大学生程序设计竞赛
    UVA
  • 原文地址:https://www.cnblogs.com/wjw1014/p/14415225.html
Copyright © 2011-2022 走看看