ElementUI 組件 Percentage 進度條
Percentage 進度條基礎用法
<el-progress :percentage="100" status="success"></el-progress>
其中 :percentage 的值可以是變量(:percentage="percentageNum"),不然也不能實時顯示進度
重難點還是怎么實時獲取后天進度、總量。思路就是:
1.后台設置一個全局變量,項目運行一步,這個全局變量就增加一下。通過函數獲取全局變量實時數據。
2.前台首先設置一個定時器(setInterval),每隔一段時間獲取一次后台全局變量的值,在頁面進行更新顯示。
后台代碼
定義兩個方法。一個獲取全局變量返回前台顯示。另一個方法處理項目需要的正常數據。
前台代碼
這里是點擊一個按鈕觸發事件后,處理需要的數據並實時顯示進度

1 var proNum = setInterval(function(){ 2 axios.post(host+'/groupData',{ 3 method: 'checkProgress', 4 }) 5 .then(res=>{ 6 if(res.data.result_code == "success"){ 7 that.progressNum = res.data.data; 8 that.percentageNum = (that.progressNum/that.strategyTotal)*100 9 } 10 }) 11 }, 1000);

1 axios.post( host+'/groupData', { 2 method:'addGroup', 3 strategyNum: that.strategyNum, 4 }) 5 .then(res => { 6 clearInterval(proNum); 7 that.progressNum = 0; 8 that.percentageNum = 0; 9 if (res.data.result_code == "success") { 10 that.groupData = res.data.data; 11 //that.page = res.data.page; 12 } else { 13 that.$notify({ title: '警告', message: '連接異常', type: 'warning', duration: 4500, }); 14 } 15 })