微信小程序开发中触发 onshow的几种特殊情况
今天在开发微信小程序上传图片的时候,发现执行了 onshow 方法,经查询资料,发现了以下特殊的情况会执行onshow.
如果你先调用了 wx.chooseImage 或 wx.chooseMedia,用户在选择完图片返回页面时,可能会触发 onShow:
wx.chooseImage({ success(res) { // 用户选择完图片返回页面,此时页面可能触发 onShow const tempFilePaths = res.tempFilePaths; wx.uploadFile({ url: 'https://example.com/upload', filePath: tempFilePaths[0], name: 'file', success() { // uploadFile 本身不会触发 onShow } }); } });
如果你观察到
onShow 被调用了,请检查:-
是否同时调用了
wx.chooseImage/wx.chooseMedia/wx.chooseFile? -
是否有页面跳转后再返回的操作?
-
是否有其他逻辑导致页面重新可见?
浙公网安备 33010602011771号