小程序真机调试报错:
[publib]:2 Uncaught (in promise) thirdScriptError {“errMsg”:“hideLoading:fail:toast can’t be found”} Object

原因:
wx.showLoading与wx.hideLoading,wx.showToast与wx.hideToast没有对应,一般在打开提示(wx.showLoading)后,就要关闭提示(wx.hideLoading)
之前不会这么严格,不会报错,版本更新后的就必须要两者对应了

解决办法:
在用到wx.showLoading和wx.showToast的时候,适当地方关闭就行

思路:
定义两个变量 isShowLoading = false ; isShowToast = false

① 调用 wx.hideLoading时候先判断 isShowloading,为true才能执行,否则不执行;接着执行showLoading 函数,执行结束将 isShowLoading 设为 true。

② 调用 wx.hideToast时候判断 isShowToast ,为 true就执行 ,否则不执行;接着执行showToast函数,执行结束将 isShowToast设为 true。

每次使用wx.hideLoading 和 wx.hideToast 都要做判断

var isShowLoading = false;
var isShowToast = false;

Page({
	start: function() {
	//调用 wx.hideLoading 时候先判断 isShowloading
	if (!isShowLoading) {
		wx.hideLoading();
	 }
	wx.showLoading({
	  title: '加载'
	})
	isShowLoading = true;
	
	// wx.showToast 时候判断 isShowloading
	if (!isShowToast) {
		wx.hideToast();
	}
	wx.showToast({
	  title: '提示',
	});
	isShowToast = true;
	}
	
});
Logo

腾讯云面向开发者汇聚海量精品云计算使用和开发经验,营造开放的云计算技术生态圈。

更多推荐