element-ui 文件上传类型及大小限制

2023-05-16

 <el-upload ref="upload" :auto-upload="false" :limit="1" accept=".pdf" action=""
                           :file-list="fileList" :on-change="handleChange" :on-remove="handleRemove"
                >
                  <el-button slot="trigger" size="small" type="primary">选取文件</el-button>
                  <div slot="tip" class="el-upload__tip">只能上传pdf文件,且不超过50M</div>
                </el-upload>
  // 文件
    handleChange(file, fileList) {
      const isLt5M = file.size / 1024 / 1024 < 50
      if (!isLt5M) {
        this.$message.error('上传文件大小不能超过 50MB')
        file = null
        fileList = []
        this.$refs.upload.clearFiles() // 清除前端显示的文件列表
      } else {
        if (file.status === 'ready') {
          this.uploadFile = file.raw
        }
      }
    },

    handleRemove(file, fileList) {
      if (file.uid === this.uploadFile.uid) {
        this.uploadFile = {}
      }
    },
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

element-ui 文件上传类型及大小限制 的相关文章

随机推荐