打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
el-upload 文件类型、大小限制
<el-upload
          :before-upload="beforeUpload"                
</el-upload>


beforeUpload(file){

        var testmsg=file.name.substring(file.name.lastIndexOf('.')+1)

        const extension = testmsg === 'pdf' ||  testmsg === 'PDF';

        const isLt50M = file.size / 1024 / 1024 < 50

        if(!extension ) {

          this.$message({

            message: '上传文件只能是pdf格式!',

            type: 'error'

          });

          return false;//必须加上return false; 才能阻止

        }

        if(!isLt50M) {

          this.$message({

            message: '上传文件大小不能超过 50MB!',

            type: 'error'

          });

          return false;

        }

        return extension ||  isLt50M

      }

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
成功可编辑el-table使用el- upload上传文件
如何使用elemen-ui实现文件的上传与下载
Puppeteer笔记(五):Puppeteer文件上传
4 Koa实战 - Restful API
Element+vue.js 实现文件模板下载,和Upload 上传文件带参数
vue下载excel模板并提交数据
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服