uniapp编译为app,页面中同时多个请求,如何配置只显示一个loading

loading.js

var reqNum = 0;
export default {
    methods: {
        startLoading() {
            if (reqNum === 0) {
                uni.showLoading({
                    title: '正在加载,请稍候',
                    mask: false,
                })
            }
            reqNum++
        },
        endLoading() {
            if (reqNum <= 0) return
            reqNum--
            if (reqNum === 0) {
                uni.hideLoading();
            }
        },
    }
}

使用页面

import mixinLoading from '../components/loading.js';
export default {
        name: "userAlarm",
        mixins: [mixinLoading],
                methods:{
                  //示例请求
                      getEventNumByHour() {
                this.startLoading();
                this.post({
                    showLoading:false,
                    url: Api.URL.URL_EventNumByHourApp(),
                    data: {
                        queryStartTime: this.currentParam.alarmTimeStart,
                        queryEndTime: this.currentParam.alarmTimeEnd,
                    },
                    success: (res) => {
                        this.endLoading();
                        this.getEventNumByInterceptHour(res.data);
                    },
                    fail: (err) => {
                        this.endLoading();
                        console.error(err);
                    },
                });
            },
            getEventNumByInterceptHour(array) {
                    this.startLoading();
                this.post({
                    showLoading:false,
                    url: Api.URL.URL_GetEventNumByInterceptHour(),
                    data: {
                        queryStartTime: this.currentParam.alarmTimeStart,
                        queryEndTime: this.currentParam.alarmTimeEnd,
                    },
                    success: (res) => {
                        this.endLoading();
                        let lineDataList = [];
                        
                    },
                    fail: (err) => {
                        this.endLoading();
                        console.error(err);
                    },
                });
            },

                      .....
  }
}
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容