upload上传文件限制文件类型

beforeFileUpload(file){
      let fileName = file.name;
      let uid = file.uid
      let pos = fileName.lastIndexOf(".");
      let lastName = fileName.substring(pos, fileName.length);
      console.log(lastName,lastName.toLowerCase());
      if (
        lastName.toLowerCase() !== ".pdf" &&
        lastName.toLowerCase() !== ".doc"&&
        lastName.toLowerCase() !== ".docx"&&
        lastName.toLowerCase() !== ".zip"&&
        lastName.toLowerCase() !== ".rar"&&
        lastName.toLowerCase() !== ".xls"&&
        lastName.toLowerCase() !== ".xlsx"
      ) {
        this.$message.error("文件必须为.pdf .doc .docx .zip .rar .xls .xlsx类型");
        return false;
      }
    }

你可能感兴趣的:(upload上传文件限制文件类型)