1. Scenario:
After the new goods orders, personal switched to the center of the page, found no increase in the number of orders, because the applet does not request the latest server data
2, the solution:
We usually call an initialization method in the onLoad page hook function, this method obviously does not meet our needs;
So the official documentation provided another hook function: onShow; this method will be re-executed when the page is displayed so that you can solve this problem
The official document: https://developers.weixin.qq.com/miniprogram/dev/framework/app-service/route.html# routing
3, the following is found onshow may cause problems in the collection of data:
Android phone onShow will be triggered twice, but in IOS phone is not encountered such a situation (I did not find the problem)
Attached solution:
If the method must be placed onShow performed, it is possible to avoid this problem by providing a switch
1, define a Boolean value in data: hadOnShow: false
2, the Boolean value determining function onshow
onShow: function () {
let _this = this
if (_this .data.hadOnShow) {
return
}
_this .setData({
hadOnShow: true
})
console.log("onshowing")
//调用初始化方法
},