element上传附件(el |
您所在的位置:网站首页 › 上传api › element上传附件(el |
element上传附件(el-upload 超详细)
经常会有人问我上传文件怎么做,这个功能其实比较常见的功能,后台管理系统基本上都有,这就离不开element的el-upload,虽然配置项很多,我们慢慢看,先看结构代码,之中有注释: //这里是上传了那些文件的提示,我没有要默认的文件提示 {{tag.name}} 上传附件data中: //上传后的文件列表 fileList: [], // 允许的文件类型 fileType: [ "pdf", "doc", "docx", "xls", "xlsx","txt","png","jpg", "bmp", "jpeg"], // 运行上传文件大小,单位 M fileSize: 50, // 附件数量限制 fileLimit: 5, //请求头 headers: { "Content-Type": "multipart/form-data" },methods中: //上传文件之前 beforeUpload(file){ if (file.type != "" || file.type != null || file.type != undefined){ //截取文件的后缀,判断文件类型 const FileExt = file.name.replace(/.+\./, "").toLowerCase(); //计算文件的大小 const isLt5M = file.size / 1024 / 1024 { if(res.data.id != '' || res.data.id != null){ this.fileList.push(item.file);//成功过后手动将文件添加到展示列表里 let i = this.fileList.indexOf(item.file) this.fileList[i].id = res.data.id;//id也添加进去,最后整个大表单提交的时候需要的 if(this.fileList.length > 0){//如果上传了附件就把校验规则给干掉 this.fileflag = false; this.$set(this.rules.url,0,'') } //this.handleSuccess(); } }) }, //上传成功后的回调 handleSuccess(){ },齐活,如果你觉得还ok,那就点个赞吧,哈哈哈 |
今日新闻 |
推荐新闻 |
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |