1、无效代码:
if (wx.showLoading) {
wx.showToast({
icon: 'loading',
title: 'Loading',
mask: true
})
};
wx.showLoading({ mask: true, title: '加载中...' })
异步获取数据后
wx.hideLoading();
测试结果
在微信开发者工具和iOS上都能正常隐藏loading框,安卓手机上无法隐藏。
2、解决办法:
(1):设置定时
setTimeout(() => {
wx.hideLoading();
wx.showToast({
icon: 'loading',
title: 'Loading',
mask: true
})
}, 100);
(2):检查是否与wx.navigateBack({ })连用,如果联合使用则去掉一个
3、wx.navigateBack({ })相关error:
(1):wx.showToast尽量不要与其连用(放在一块儿使用)会造成遮罩(Android机);
(2):wx.showModal与其连用
wx.showModal({
title: '提示',
content:res.msg,
success: function(res) {
wx.navigateBack();
}
});
4、wx.navigateBack传递json对象:
(1):传递json数据(对象)
//e为页面选择的数据
函数名:function(e){
var page = this;
var item = e.currentTarget.dataset.index;
if (item != null){
wx.navigateTo({
url: '/pages/xxx/xxx?item=' + JSON.stringify(item),
})
}else{
wx.showToast({
title: "文件出错!",
image: "/images/img/icon-warning.png"
});
}
}
(2):解析json数据(页面接收参数 解析json)
//pages/xxx/xxx接收参数
onLoad: function (options) {
var page = this;
var item = JSON.parse(options.item);
},