react

 

1.安装react脚手架新建项目并运行

==>1. npm install -g create-react-app

==>2. create-react-app start-app

==>3. cd start-app 

==>4. npm start 
2.如何安装并使用yarn

==>1.macOS 

brew install yarn

==>2.window

choco install yarn

注释:Chocolatey 是一个 Windows 专用的软件包管理工具 自行百度

==>3.yarn init

==>4.yarn add [package]@[version]

==>5.yarn remove [package]

==>6.yarn install

3.React生命周期

==>1.

4.事件点击默认的两种写法

5. react生命周期函数(

  1. Mounting(加载阶段)
  2. Updating(更新阶段)
  3. Unmounting(卸载阶段)

)

==>1.getDefaultProps()   -->设置默认的props,也可以用dufaultProps设置组件的默认属性
==>2.getInitialState() -->初始化state,可以直接在constructor中定义this.state

==>3.componentWillMount() --> 组件加载时只调用,以后组件更新不调用,整个生命周期只调用一次,此时可以修改state 调用接口也在此进行
==>4.render() --> 创建虚拟dom,进行diff算法,更新dom树
==>5.componentDidMount() -->组件渲染之后调用,只调用一次
==>6.componentWillReceivePorps(nextProps)-->组件加载时不调用,组件接受新的props时调用

==>7.shouldComponentUpdate(nextProps, nextState) --> 组件接收到新的props或者state时调用,return true就会更新dom(使用diff算法更新),return false能阻止更新(不调用render)

==>8.componentWillUpdata(nextProps, nextState) -->组件加载时不调用,只有在组件将要更新时才调用,此时可以修改state

==>9.componentDidUpdate() -->组件加载时不调用,组件更新完成后调用

==>10.componentWillUnmount() -->卸载组件

6.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值