|
本帖最后由 周大胖子 于 2021-2-25 09:55 编辑
-
- 生命周期函数: 在某一个生命周期组件会自动执行的函数 ;
-
- Mouting:
-
- componentWillMount(){
- // 这个函数在组件即将被[挂载 意思就是第一次挂载 只有一次 ]到页面时[之前]自动执行
- // 也在 render() 之前
- }
-
- componentDidMount(){
- // 这个函数在组件即将被[挂载 意思就是第一次挂载 只有一次 ]到页面时[之后]自动执行
- // 也在 render() 之后
- }
- render(){
-
- }
-
-
- Updation:
-
- shouldComponentUpdate()
- {
- // 组件被更新之前执行
- // 该函数 使用要求返回一个布尔值 例如
- return ture; // 如果返回false 表示组件不需要更新,页面也不会有任何反馈
- }
- componentWillUpdate()
- {
- // 组件更新之前执行
- // 如果 shouldComponentUpdate 返回 false 则该函数不会执行
-
- }
- componentDidUpdate()
- {
- // 组件更新完成之后被执行
- }
-
- componentWillReceiveProps(){
- // 如果 props 没有 则该函数不会被执行
- // 只要父组件的render() 重新执行了, 子组件的 此函数就会被重新执行
- }
-
-
- Unmounting:
-
- componentWillUnmout(){
- // 当组件即将从页面剔除时 执行
- }
-
复制代码
|
|