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);
},
});
},
.....
}
}