el-upload + accept限制上传的文件格式

/**
 * kevin 2021/1/4
 * @description el-upload + accept限制上传的文件格式
 * @param e 校验的类型
 * @returns {string | null}
 */
export function acceptFile(e) {
  const allowHook = {
    video: '.mp4, .ogv, .ogg, .webm',
    audio: '.wav, .mp3, .ogg, .acc, .webm, .amr',
    file: 'doc,.docx,.xlsx,.xls,.pdf',
    excel: 'xlsx,.xls',
    img: '.jpg, .jpeg, .png, .gif'
  }
  if (e) {
    return allowHook[e]
  }
  let srt = null
  for (const k in allowHook) {
    srt += allowHook[k]
  }
  return srt
}

 

posted @ 2021-04-25 13:10  吃不棒的胖胖糖  阅读(2547)  评论(0编辑  收藏  举报