小程序真機調試報錯:
[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;
}
});