基于Element的请求接口进度条

<template>
  <div>
    <el-progress :percentage="percentage" color="#409eff"  class="jdt_nr" v-show="jdt"></el-progress>
    <el-button type="primary"
               icon="el-icon-download"
               @click="abc()">开始请求</el-button>
  </div>
</template>
<script>
export default {
    data() {
        return {
            jdt:false,//进度条隐藏
            percentage: 0, //进度条值
            timeStart:''进度条计时
        };
    },
    methods: {
        abc(param){
            this.jdt=true
            this.loadingtuo = this.$loading({
                lock: true,
                text: "请稍等....",
                target: document.querySelector(".drts") // 设置加载动画区域
            });
            let that=this
            axios({
                url:"https://api.coindesk.com/v1/bpi/currentprice.json",
                method:'get',
            }).then(function (res) {
                that.percentage = 100;
                that.jdt=false;
                that.loadingtuo.close();

            }).catch(function (error) {
                console.log(error);
            });
        },
        increase() {
            var that=this;
            that.timeStart = setInterval(() => {
                if (that.percentage < 95) {
                    that.percentage += 5;
                }
                if (that.percentage > 100) {
                    that.percentage = 100;
                }
            }, 300);
        },
        increaseend(){
            var that=this;
            that.percentage = 100;
            clearInterval(this.timeStart);
        }

    },
    watch: {
        // 监听loading状态控制进度条显示
        jdt(value, newValue) {
            const that = this;
            console.log(value+"----newValue----"+newValue)
            if (value) {
                that.increase();
            } else {
                that.increaseend();
            }
        },
    },

};
</script>
<style>
  .jdt_nr{width:50%;margin:0 auto;z-index:10001;top:50%;margin-top:-31px;text-align:center;position:absolute;margin-left:25%}
  .sbxxdrjzdh .el-loading-spinner .circular{display: none;}
</style>


 

  • 5
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值