uni-app的生命周期
应用的生命周期函数
- onLaunch 初始化页面时触发
- onShow 当uni-app启动,或从后台进入前台显示
- onHide 从前台进入后台
- onError 当uni-app 报错时触发
页面的生命周期函数
- onLoad 页面初次加载 (只会显示一次)
- onShow 进入页面
- onReady 页面渲染 (只会显示一次)
- onHide 页面隐藏
- onUnload 页面销毁
- onPullDownRefresh 监听用户下拉动作,一般用于下拉刷新
页面单独下拉刷新
page.json 中 使用 style 配置 enablePullDownRefresh: true (全局)
监听下拉刷新:onPullDownRefresh
onPullDownRefresh() {
console.log('触发了下来刷新')
.....
uni.stopPullDownRefresh()
//停止刷新
}
通过调用API来开启下拉刷新
调用uni.startPullDownRefresh() 来触发下拉刷新
调用 uni.stopPullDownRefresh() 来停止刷新
onReachBottom
页面滚动到底部的事件(不是scroll-view滚到底),常用于下拉下一页数据(页面触底,触发)
通过page 配置项 onReachBottomDistance 来设置上拉事件触发的距离,默认为50px