小程序:Taro在微信小程序中的生命周期

一、Taro的本身生命周期

序号 Taro 微信小程序 说明 备注
1 componentWillMount onLoad /app中的onLaunch
2 componentDidMount onReady/入口文件app中的onLaunch
3 componentDidShow onShow
4 componentDidHide onHide
5 componentDidCatchError onError
6 shouldComponentUpdate
7 componentWillUpdate
8 componentDidUpdate
9 componentWillUnmount onUnload
10 componentDidNotFound onPageNotFound

生命周期
componentWillMount
在微信小程序中这一生命周期方法对应页面的onLoad或入口文件app中的onLaunch

componentDidMount
在微信小程序中这一生命周期方法对应页面的onReady或入口文件app中的onLaunch,在 componentWillMount后执行

componentDidShow
在微信小程序中这一生命周期方法对应 onShow

componentDidHide
在微信小程序中这一生命周期方法对应 onHide

componentDidCatchError
错误监听函数,在微信小程序中这一生命周期方法对应 onError

componentDidNotFound
页面不存在监听函数,在微信小程序中这一生命周期方法对应 onPageNotFound

shouldComponentUpdate
页面是否需要更新

componentWillUpdate
页面即将更新

componentDidUpdate
页面更新完毕

componentWillUnmount
页面退出,在微信小程序中这一生命周期方法对应 onUnload

二、Taro在微信小程序开发中特有的生命周期

  1. onPullDownRefresh: 页面相关事件处理函数–监听用户下拉动作

  2. onReachBottom: 页面上拉触底事件的处理函数

  3. onShareAppMessage: 用户点击右上角转发

  4. onPageScroll: 页面滚动触发事件的处理函数

  5. onTabItemTap: 当前是 tab 页时,点击 tab 时触发

  6. componentWillPreload: 预加载,只在微信小程序中可用

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容