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
  }
相关推荐
掘金安东尼3 分钟前
Chrome 17 岁了——我们的浏览器简史
前端·javascript·github
袁煦丞3 分钟前
群晖NAS FTP远程文件仓库全球访问:cpolar内网穿透实验室第524个成功挑战
前端·程序员·远程工作
前端小巷子7 分钟前
JS 打造动态表格
前端·javascript·面试
excel19 分钟前
从卷积到全连接:用示例理解 CNN 的分层
前端
UNbuff_020 分钟前
HTML 各种事件的使用说明书
前端·html
Mr. Cao code24 分钟前
探索OpenResty:高性能Web开发利器
linux·运维·服务器·前端·nginx·ubuntu·openresty
百思可瑞教育1 小时前
ActiveMQ、RocketMQ、RabbitMQ、Kafka 的全面对比分析
vue.js·分布式·rabbitmq·rocketmq·activemq·北京百思可瑞教育·百思可瑞教育
li35748 小时前
将已有 Vue 项目通过 Electron 打包为桌面客户端的完整步骤
前端·vue.js·electron
Icoolkj9 小时前
VuePress 与 VitePress 深度对比:特性、差异与选型指南
前端·javascript·vue.js
excel9 小时前
CNN 分层详解:卷积、池化到全连接的作用与原理
前端