elementui轉base64上傳文件


<el-upload
  ref='upload'
  :auto-upload='false'
  :file-list="fileList"
  :multiple='false'
  :limit="1"
  :on-exceed="handleExceed"
  :http-request="uploadFiles"
  accept="image/jpeg,image/gif,image/png"
  action=''
  :on-change='changeUpload'     
  >
 <el-button slot="trigger" size="mini" type="primary">選取圖片</el-button>
 <span>&nbsp;</span>
 <el-button @click='uploadFiles' size="mini" type="primary">點擊上傳</el-button>
</el-upload>
//點擊上傳圖片,上傳成功返回圖片路徑 
uploadFiles(){
  var That=this;
 let file=this.$refs.upload.$refs['upload-inner'].$refs.input; //獲取文件數據
 let fileList=file.files;   
 var imgFile;
 let reader = new FileReader();   //html5讀文件
 reader.readAsDataURL(fileList[0]); //轉BASE64    
 reader.onload=function(e) {    //讀取完畢后調用接口
  imgFile = e.target.result;
  let obj={
    id: "loginLogo",
    configGroup: "logo",
    configItem : "loginLogo",
   itemValue : imgFile  
  }
  return BaseApi.uploadFiles(obj).then((res)=>{
    if(res.status=='SUCCESS'){
      AlertBox('圖片上傳成功!','success',true).then(()=>{
        return That.getSysLogo(); //調用獲取base64數據接口
      });
    }else{
      Alert('圖片上傳失敗',res);
      return ''
    }
  })
 
 };     
},

 

內容來自https://www.jb51.net/article/144933.htm

 


免責聲明!

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



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