el-upload--》 當action為空時,如何實現上傳功能?


  //結構 
  <img :src="imgLogo" class="logoImg fl" style="margin:0 10px;" /> <el-upload style="width: 220px" ref="newupload" class="logo-uploader fl" action="#" :show-file-list="false" :before-upload="beforeLogoImgUpload" :http-request="httpRequestLogo"> <el-button slot="trigger" size="small" icon="el-icon-upload" style="width: 115px;">選擇Logo </el-button> <div slot="tip" class="el-upload__tip"> <p>只能上傳jpg/png/gif文件,且不超過2MB</p> <p>建議上傳圖片尺寸為80*60</p> </div> </el-upload>

  

   //方法
  beforeLogoImgUpload(file) {
const isJPG = file.type == "image/jpeg" || file.type == "image/png" || file.type == "image/gif"; const isLt2M = file.size / 1024 / 1024 < 2; if (!isJPG) { this.$message.error("上傳企業Logo圖片只能是 JPG/PNG/GIF 格式!"); return isJPG; } if (!isLt2M) { this.$message.error("上傳企業Logo圖片大小不能超過 2MB!"); return isLt2M; } this.multfileLogoImg = file; return isJPG && isLt2M; }, httpRequestLogo(data) { let _this = this; let rd = new FileReader(); // 創建文件讀取對象 this.logoFile = data.file; //傳遞給后端的參數 rd.readAsDataURL(this.logoFile); // 文件讀取裝換為base64類型 rd.onloadend = function(e) { _this.imgLogo = rd.result; // 圖片回顯 _this.fd = new FormData(); _this.fd.append("token", _this.token); //傳其他參數 _this.fd.append("file", _this.logoFile); //傳其他參數 api_bcs.saveFileUrl(_this.fd).then(res => { if (res) { _this.delLogoList.push(res.data); _this.imgLogoParm = res.data; _this.$message({ showClose: true, type: "success", message: "設置成功" }); store.commit("UPDATE_SYSHEADER", _this.imgLogo); //企業logo } }); }; },

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM