vue 一直显示数据加载中的解决方案之一

现象描述

当页面加载的时候,一直显示“数据加载中”的loading。


解决方案之一

出现这样的原因,可能是该页面同时在加载两个或者两个以上的api数据请求,即多次调用后台接口。
解决思路: 同步执行,即是一个方法接一个方法的执行。


示例

(一)一直出现 数据加载loading 示例代码:

mounted() {
    this.bug1();
    this.bug2();
    this.bug3();
},

//连接api函数
bug1() {
    this.$http.post(this.HOST + '/cust/action1.do', {
        'projid': this.$store.state.core.loginFormInfo.projId,
        'custid': this.clientId
    }, {
        emulateJSON: true
    }).then((response) => {
        if(response.data.success) {}
        if(!response.data.success) {}
    })
},
bug2() {
    this.$http.post(this.HOST + '/cust/action2.do', {
        'projid': this.$store.state.core.loginFormInfo.projId,
        'custid': this.clientId
    }, {
        emulateJSON: true
    }).then((response) => {
        if(response.data.success) {}
        if(!response.data.success) {}
    })
},
bug3() {
    this.$http.post(this.HOST + '/cust/action3.do', {
        'projid': this.$store.state.core.loginFormInfo.projId,
        'custid': this.clientId
    }, {
        emulateJSON: true
    }).then((response) => {
        if(response.data.success) {}
        if(!response.data.success) {}
    })
},

(二)解决方案 示例代码:

mounted() {
    // 1.先执行第一个
    this.bug1();
},



bug1() {
    this.$http.post(this.HOST + '/cust/action1.do', {
        'projid': this.$store.state.core.loginFormInfo.projId,
        'custid': this.clientId
    }, {
        emulateJSON: true,
        async: false,
    }).then((response) => {
            // 2.执行第二个
            this.bug2()
        }
        if(!response.data.success) {}
    })
},
bug2() {
    this.$http.post(this.HOST + '/cust/action2.do', {
        'projid': this.$store.state.core.loginFormInfo.projId,
        'custid': this.clientId
    }, {
        emulateJSON: true,
        async: false,
    }).then((response) => {
            // 3.执行第三个
            this.bug3()
        }
        if(!response.data.success) {}
    })
},
bug3() {
    this.$http.post(this.HOST + '/cust/action3.do', {
        'projid': this.$store.state.core.loginFormInfo.projId,
        'custid': this.clientId
    }, {
        emulateJSON: true,
        async: false,
    }).then((response) => {
        if(response.data.success) {}
        if(!response.data.success) {}
    })
},

即是:三个在 mounted() 中的执行的请求后台api函数 依次 一个一个 执行。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

牙云敏同学

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值