關於el-upload上傳


 <el-upload
                class="edit-input-upload"
                :action="config.baseUrl + '/joinus/candidate/updateFile'"
                :limit="1"
                :before-upload="beforeAvatarUpload"
                :on-success="fileNumber"
                accept=".doc,.dot,.DOC,.DOT.pdf,.PDF"
                :file-list="fileList"
                ref="uploadResuMe"
              >
       <div class="upload-box">{{$t('joinUs.browse')}}</div>
</el-upload>


//錯誤提示
<div class="upload-error">
  <p v-show="uploadErrorFileSize">× {{$t('joinUs.uploadError1')}}</p>
  <p v-show="uploadErrorFileType">× {{$t('joinUs.uploadError2')}}</p>
</div>

methods:

  //限制上傳格式和大小
  beforeAvatarUpload (file) {
const isDOC = file.type === 'application/msword'; const isPDF = file.type === 'application/pdf'; const isLt5M = file.size / 1024 / 1024 < 5; if (!isDOC && !isPDF) { this.uploadErrorFileSize = true } else { this.uploadErrorFileSize = false } if (!isLt5M) { this.uploadErrorFileType = true } else { this.uploadErrorFileType = false } return (isDOC || isPDF) && isLt5M; },

   //成功后獲取文件名 和 文件路徑 fileNumber (response, file, fileList, result) {
this.fileListNum = fileList.length this.ruleForm.fileUrl = response.data.filePath this.ruleForm.originName = response.data.fileName },
//清空已上傳的文件 clearUpload () {
this.$refs.uploadResuMe.clearFiles() },

 


免責聲明!

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



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