zl程序教程

您现在的位置是:首页 >  其他

当前栏目

小程序onShow

2023-09-27 14:24:29 时间
/**
 * 生命周期函数--监听页面加载
 */
onLoad: function(options) {
    let that = this;
    const openid = app.globalData.openid || Storage.get().openid;
    initNoPage(this, [{ api: "getPerson", inData: { openid }, outDataName: "user_data" }])
}

数据只加载一次。

/**
 * 生命周期函数--监听页面显示
 */
onShow: function(options) {
    let that = this;
    const openid = app.globalData.openid || Storage.get().openid;
    initNoPage(this, [{ api: "getPerson", inData: { openid }, outDataName: "user_data" }])
}

页面每访问一次都调用一次接口。

当页面数据要求及时变化的时候,可以把接口数据放入onShow中。