Element Plus 文件上传格式校验

视频格式:'video/mp4', 'video/avi', 'video/mov', 'video/wmv', 'video/flv', 'video/ts'
视频格式校验以及空文件校验:
javascript 复制代码
<el-form-item label="视频选择" prop="fileList">
              <el-upload
                style="width: 200px"
                ref="uploadRef"
                action=""
                accept=".mp4.avi.mov.wmv.flv.ts"
                v-model:file-list="formModel.fileList"
                :limit="1"
                :http-request="handlerUpload"
                :headers="headers"
                :on-success="handleSuccess"
                :before-upload="beforeAvatarUpload"
              >
                <el-button type="primary">选择文件</el-button>
              </el-upload>
            </el-form-item>
javascript 复制代码
  const beforeAvatarUpload = (rawFile) => {
    let typeList = ['video/mp4', 'video/avi', 'video/mov', 'video/wmv', 'video/flv', 'video/ts']
    if (!typeList.includes(rawFile.type)) {
      proxy.$modal.msgError('请上传视频文件!')
      return false
    } else if (rawFile.size / 1024 / 1024 <= 0) {
      proxy.$modal.msgError('请勿上传空文件!')
      return false
    }
    return true
  }
图片格式 、空文件、重复上传校验:
javascript 复制代码
 <el-form-item label="海报选择">
              <el-upload
                style="width: 200px"
                ref="imgUploadRef"
                action=""
                multiple
                :file-list="imgList"
                accept=".jpg,.png,.jpeg"
                :http-request="handlerIMGUpload"
                :headers="headers"
                :before-upload="imgBeforeAvatarUpload"
              >
                <el-button type="primary">选择图片</el-button>
              </el-upload>
            </el-form-item>
javascript 复制代码
  const imgBeforeAvatarUpload = (rawFile, file) => {
    if (
      rawFile.type !== 'image/jpeg' &&
      rawFile.type !== 'image/png' &&
      rawFile.type !== 'image/jpg'
    ) {
      proxy.$modal.msgError('请上传图片文件!')
      return false
    } else if (rawFile.size / 1024 / 1024 <= 0) {
      proxy.$modal.msgError('请勿上传空文件!')
      return false
    } else {
      let newFilelist = imgList.slice(0, imgList.length - 1)
      if (newFilelist.some((item) => item.name == rawFile.name)) {
        proxy.$modal.msgError('请勿重复上传!')
        return false
      }
    }

    return true
  }
相关推荐
Aliex_git3 分钟前
性能指标笔记
前端·笔记·性能优化
秋天的一阵风3 分钟前
🌟 藏在 Vue3 源码里的 “二进制艺术”:位运算如何让代码又快又省内存?
前端·vue.js·面试
松涛和鸣4 分钟前
48、MQTT 3.1.1
linux·前端·网络·数据库·tcp/ip·html
helloworld也报错?5 分钟前
保存网页为PDF
前端·javascript·pdf
渡我白衣5 分钟前
计算机组成原理(13):多路选择器与三态门
开发语言·javascript·ecmascript·数字电路·计算机组成原理·三态门·多路选择器
码丁_1176 分钟前
某it培训机构前端三阶段react及新增面试题
前端·react.js·前端框架
石小石Orz6 分钟前
自定义AI智能体扫描内存泄漏代码
前端·ai编程
汐泽学园6 分钟前
基于Vue的家乡旅游美食信息网站设计与实现
javascript·vue.js·html·旅游·美食
_木棠7 分钟前
uniapp:H5端reLaunch跳转后,返回还有页面存在问题
前端·uni-app
_pengliang21 分钟前
react native ios 2个modal第二个不显示
javascript·react native·react.js