• el-upload上传组件(隐藏上传按钮/隐藏文件删除标记)


    <template>
      <el-upload
        ref="uploadFile"
        :class="[showUploadBtn ? '' : 'hidden-Btn']"   //是否隐藏点击上传的按钮
        :disabled="!showUploadBtn"                     //是否隐藏文件删除标记
        action="#none"
        :http-request="uploadSectionFile"
        :on-preview="handlePreview"
        :on-remove="handleRemove"
        :before-remove="beforeRemove"
        :on-change="fileChange"
        :auto-upload="false"
        multiple
        :on-exceed="handleExceed"
        :file-list="fileList"
      >
        <el-button size="small" type="primary">点击上传</el-button>
      </el-upload>
    </template>
    
    <script>
    export default {
      name: "UploadFiles",
      props: {
        files: {
          type: Array,
          default: () => [],
        },
        /*是否显示上传文件按钮、是否显示文件删除×号*/
        showUploadBtn: {
          type: Boolean,
          default: true,
        },
      },
      data() {
        return {
          fileList: this.files,
        };
      },
      methods: {
        handleRemove(file, fileList) {
          console.log(file, fileList);
          // 改变文件列表
          this.fileList = fileList;
        },
        handlePreview(file) {
          console.log("handlePreview:", file);
          if (file.url) {
            window.open(file.url);
          }
        },
        handleExceed(files, fileList) {
          this.$message.warning(
            `当前限制选择 3 个文件,本次选择了 ${files.length} 个文件,共选择了 ${
              files.length + fileList.length
            } 个文件`
          );
        },
        beforeRemove(file, fileList) {
          return this.$confirm(`确定移除 ${file.name}?`);
        },
        // param是自带参数。
        // this.$refs.uploadFile.submit()会自动调用 httpRequest方法.在里面取得file
        uploadSectionFile(param) {
          var fileObj = param.file;
          // FormData 对象
          var form = new FormData();
          // 文件对象
          form.append("file", fileObj);
          console.log("dfdg:");
          console.log(form);
          let arr = [];
          this.fileList.forEach((element) => {
            let formData = new FormData();
            formData.append("file", element);
            arr.push(formData);
          });
        },
        // fileList 是文件列表发生变化后,返回的修改后的列表对象,这里直接赋值
        fileChange(file, fileList) {
          console.log(file.raw);
          // 改变文件列表
          this.fileList = fileList;
        },
      },
    };
    </script>
    
    <style scoped lang="scss">
    .hidden-Btn {
      /deep/ .el-upload {
        display: none;
      }
    }
    </style>
  • 相关阅读:
    Android 跨进程通信之AIDL
    Android开发 USB开发
    Socket实现客户端和服务端
    Validation 内置校验
    BigDecimal工具类
    Visio 容器工具
    SQLite 通过.sql文件导入导出数据
    Go 常用内置包简介
    视频分片.上传
    PS 编辑形状
  • 原文地址:https://www.cnblogs.com/yiliangmi/p/15305186.html
Copyright © 2020-2023  润新知