欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

vue?elementui?大文件進(jìn)度條下載功能實(shí)現(xiàn)

 更新時(shí)間:2025年01月13日 10:56:49   作者:RW~  
本文介紹了如何使用下載進(jìn)度條來(lái)展示下載進(jìn)度的方法,并展示了相關(guān)的效果圖,結(jié)合實(shí)例代碼介紹了vue?elementui?大文件進(jìn)度條下載的方法,感興趣的朋友一起看看吧

效果圖展示:

下載進(jìn)度條

<el-card class="box-card" v-if="downloadProgress > 0">
	<div>正在下載文件...</div>
	<el-progress :text-inside="true" :stroke-width="26" :percentage="downloadProgress" status="success"></el-progress>
</el-card>

下載方法

downloadFile(row) {
   const xhr = new XMLHttpRequest();
   xhr.open('GET', row.certificatePdf, true);
   xhr.responseType = 'blob';
   // 監(jiān)聽(tīng)下載進(jìn)度
   xhr.onprogress = (event) => {
       if (event.lengthComputable) {
           this.downloadProgress = Math.floor((event.loaded / event.total) * 100);
       }
   };
   // 下載完成
   xhr.onload = () => {
       if (xhr.status === 200) {
           const blob = xhr.response;
           const link = document.createElement('a');
           link.href = window.URL.createObjectURL(blob);
           link.download = row.certificateName + '.pdf';
           document.body.appendChild(link);
           link.click();
           document.body.removeChild(link);
           this.downloadProgress = 0; // 重置進(jìn)度條
       }
   };
   // 錯(cuò)誤處理
   xhr.onerror = () => {
       console.error('下載失敗');
       this.downloadProgress = 0; // 重置進(jìn)度條
   };
   xhr.send();
},
.box-card {
  position: fixed;
  right: 20px;
  top: 100px;
  width: 300px;
  font-size: 12px;
}

到此這篇關(guān)于vue elementui 大文件進(jìn)度條下載功能實(shí)現(xiàn)的文章就介紹到這了,更多相關(guān)vue elementui 進(jìn)度條下載內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評(píng)論