这里使用的是5+自带的等待框:
plus.nativeUI.showWaiting(); //等待框开启
plus.nativeUI.closeWaiting(); //等待框关闭
参考:https://blog.csdn.net/weixin_44285250/article/details/87918882
不过有的时候会出现这样的问题,当我用ajax请求数据的时候,数据请求过快,导致我刚开始等待就直接关闭了,从用户的角度就是看不到加载的等待框。所以这边加了个延时操作setTimeout:
setTimeout(function() {
plus.nativeUI.closeWaiting(); //等待框关闭
if (res.success) {
if (res.count <= 0) {
} else {
var flag = "";
var src = "";
var computerName = "";
var machineType = "";
var userDepartment = "";
var userName = "";
var userCode = "";
var productCode = "";
var location = "";
var type = "";
var count = res.data.length;
for (var i = 0; i < count; i++) {
var dom = document.createElement("li");
dom.className = "mui-table-view-cell mui-input-row";
if (res.data[i].flag == "0") {
flag = "待完善";
src = "../../images/dairuku.png";
}
if (res.data[i].computerName == null) {
computerName = "";
} else {
computerName = res.data[i].computerName;
}
if (res.data[i].machineType == null) {
machineType = "";
} else {
machineType = res.data[i].machineType;
}
if (res.data[i].userDepartment == null) {
userDepartment = "";
} else {
userDepartment = res.data[i].userDepartment;
}
if (res.data[i].userName == null) {
userName = "";
} else {
userName = res.data[i].userName;
}
if (res.data[i].userCode == null) {
userCode = "";
} else {
userCode = res.data[i].userCode;
}
if (res.data[i].productCode == null) {
productCode = "";
} else {
productCode = res.data[i].productCode;
}
if (res.data[i].flag == null) {
flag = "";
} else {
flag = res.data[i].flag;
}
if (res.data[i].location == null) {
location = "";
} else {
location = res.data[i].location;
}
if (res.data[i].type == null) {
type = "";
} else {
type = res.data[i].type;
}
dom.innerHTML = '<a href="javascript:;" title="ZiChanLingYong_Detail.html" id="' + res.data[i].id + '">' +
'<img class="mui-media-object mui-pull-right" src="' + src + '">' +
'<div class="mui-media-body">' +
'申请人:' + res.data[i].applier +
'<p class="mui-ellipsis">计算机名:' + computerName + ' 出厂编码:' + productCode + '</p>' +
'<span computerName="' + computerName + '" machineType="' + machineType + '" userDepartment="' +
userDepartment + '" userName="' + userName + '" userCode = "' + userCode + '" productCode="' +
productCode +
'" flag = "' + flag + '" location = "' + location + '" type = "' + type + '"></span>'
'</div>' +
'</a>';
document.getElementById("aa").appendChild(dom);
}
}
} else {
mui.toast(res.msg);
}
}, 500);
当请求返回成功的时候,加了500ms的timeout,那么不管怎么样,都能成功显示加载框。
另外,还可以在方法中添加参数:plus.nativeUI.showWaiting(“等待中...”);