ro在React基础二阶段中,我们需要完成如下的学习

  • 组件的进阶学习之。组件的通信
  • 组件的进阶学习之。深入理解prop
  • 组件的进阶学习之,组件的生命周期
  • 再次理解prop的几种设计模式
  • 高阶组件的封装

一、组件之间的通信

组件通信prpos

组件的是一个封闭的单元,如果要实现与外部的通信,就需要使用组件来进行通 接下来我们来看看,如何接受外部传入的数据

  1. 我们有两种方式来使用
  2. 在函数组件中使用props
  • 在组件的标签上传入数据
  • 在组件的内部获取数据 通过props (注意,这个获取到的是一个对象)
  1. 在类组件中使用prpos
  • 传入数据
  • 内部获取,注意这里是this.props
  1. import React from 'react'
  2. import ReactDOM, { render } from 'react-dom'
  3. import './index.css'
  4. // React.Component必须继承 必须由返回值,必须由值
  5. // import Hello from './hello'
  6. // import {Commont} from './commonent'
  7. const Commonent = function (props) {
  8. return (
  9. <h1>props: {props} </h1>
  10. )
  11. }
  12. // 注意这个root是再public下的index中的根元素的
  13. ReactDOM.render(<Commont name="jack" age={18} />, document.getElementById('root'))
  14. // 如果使用的类组件
  15. import React from 'react'
  16. import ReactDOM, { render } from 'react-dom'
  17. import './index.css'
  18. // React.Component必须继承 必须由返回值,必须由值
  19. // import Hello from './hello'
  20. // import {Commont} from './commonent'
  21. class Commont extends React.Component {
  22. render() {
  23. return (
  24. <h1>props:{this.props}</h1>
  25. )
  26. }
  27. }
  28. // 注意这个root是再public下的index中的根元素的
  29. ReactDOM.render(<Commont name="jack" age={18} />, document.getElementById('root'))

组件通信的特点

组件通信的特点有下面的这些个特点需要认真的说明一下

  1. props是可以允许有任意属性类型的
  2. props是一个只读的属性
  3. 在类组件中,推荐把props写在构造器中
  1. // prop可以是任意的类型
  2. // 注意这个root是再public下的index中的根元素的
  3. ReactDOM.render(<Commont
  4. name="jack"
  5. age={18}
  6. fmany={[1, 2, 3]}
  7. hehe={{ age: 'asdasd', sex: 'asdasd' }}
  8. jsx={<p>heheehee</p>}
  9. />, document.getElementById('root'))
  10. // 注意要传递给super
  11. class Commont extends React.Component {
  12. constructor(props){
  13. super(props)
  14. console.log(props);
  15. }
  16. render () {
  17. return (
  18. <h1>props:{this.props}</h1>
  19. )
  20. }
  21. }

组件的常见通信方式

父 =====> 子

实际上,父组件丢到子组件,就是利用的props属性

  1. import React from 'react'
  2. import ReactDOM from 'react-dom'
  3. import './index.css'
  4. class Commont extends React.Component {
  5. constructor() { }
  6. state = {
  7. lastName: '王'
  8. }
  9. render () {
  10. return (
  11. <div>
  12. <h1>props:{this.props}</h1>
  13. <Childen props={this.state.lastName}></Childen>
  14. </div>
  15. )
  16. }
  17. }
  18. const Childen = function (props) {
  19. return (
  20. <h1>父组件的数据 {props}</h1>
  21. )
  22. }
  23. // 注意这个root是再public下的index中的根元素的
  24. ReactDOM.render(<Commont />, document.getElementById('root'))

子 =====> 父

子到父要使用自定义事件,这个和vue中$emit有异曲同工之妙, 核心就是自定义事件

  1. import React from 'react'
  2. import ReactDOM from 'react-dom'
  3. import './index.css'
  4. class Childen extends React.Component {
  5. constructor(props) {
  6. super(props)
  7. }
  8. handerClick = () => {
  9. this.props.getMessage('hehhehehehhe')
  10. }
  11. render () {
  12. return (
  13. <div>
  14. <h1>点击发送数据到父组件 {}</h1>
  15. <button onClick={this.handerClick}>点击发送信息</button>
  16. </div>
  17. )
  18. }
  19. }
  20. class Commont extends React.Component {
  21. state = {
  22. lastName: '王',
  23. }
  24. // 自定义事件来触发
  25. getMessage = (data) => {
  26. console.log(data);
  27. this.setState({
  28. lastName: data
  29. })
  30. }
  31. render () {
  32. return (
  33. <div>
  34. <h1>props:{this.state.lastName}</h1>
  35. <Childen getMessage={this.getMessage}></Childen>
  36. </div>
  37. )
  38. }
  39. }
  40. // 注意这个root是再public下的index中的根元素的
  41. ReactDOM.render(<Commont />, document.getElementById('root'))

兄弟组件之间的数据传递

兄弟之间的数据传递是一个非常重要的点 这里的核心思想,就是状态提升,提取到公共的方法上去就好了

  1. import React from 'react'
  2. import ReactDOM from 'react-dom'
  3. import './index.css'
  4. class Childen1 extends React.Component {
  5. constructor(props) {
  6. super(props)
  7. }
  8. render () {
  9. return (
  10. <div>
  11. <h1>数据 {this.props.conut}</h1>
  12. </div>
  13. )
  14. }
  15. }
  16. class Childen2 extends React.Component {
  17. constructor(props) {
  18. super(props)
  19. }
  20. render () {
  21. return (
  22. <div>
  23. <button onClick={() => this.props.incunment}>点击发送信息</button>
  24. </div>
  25. )
  26. }
  27. }
  28. class Commont extends React.Component {
  29. state = {
  30. conut: 0
  31. }
  32. // 自定义事件来触发
  33. incunment = (data) => {
  34. this.setState({
  35. conut: conut + 1
  36. })
  37. }
  38. render () {
  39. return (
  40. <div>
  41. <Childen1 count={this.state.conut}></Childen1>
  42. <Childen2 incunment={this.incunment()}></Childen2>
  43. </div>
  44. )
  45. }
  46. }
  47. // 注意这个root是再public下的index中的根元素的
  48. ReactDOM.render(<Commont />, document.getElementById('root'))

context上下文

这个东西的出现是解决了,多层次嵌套的问题 比如下面的这个例子,laozhuz => grandpa => father => son,这个时候我们就可以使用context这个组件进行数据传递了,

核心主要有两个 image.png 使用的时候就把在最近的一个父组件上,包裹一个Provider组件,在需要拿数据的地方拿一个Consumer包裹起来就好了 image.pngimage.png

二、深入的理解prop

这里呢,我们来深入的了解一下我们的prop,实际上,这个prop还有更多的属性 还有方法,它的api也一直在更新迭代

children属性

children属性很简单,表示的是组件标签的子节点,当组件有子节点的时候,prop就会有这个属性 image.png image.png

prop校验

这个东西。和我们的vue中的那个prop是基本上是一致的,我们需要对数据进行一些校验

  • 如果组件不进行数据校验,那么就会有如下的情况发生
  1. const App = props => {
  2. const arr = props.colors
  3. const lis = arr.map( ( item,index )=> <li key={index}> {item.name} </li> )
  4. return <ul> {lis} </ul>
  5. }
  6. //如果你传入的是不合法的属性,就会报错
  • image.png
  1. 使用说明
  • 需要注意的是,我们的这个是另外需要引入的

    1. npm install props-types
  • 再代码中使用 ```javascript import PropTypes from ‘prop-types’

const App = prop => { const arr = props.colors const lis = arr.map( ( item,index )=>

  • {item.name}
  • ) return
      {lis}
    } // 添加校验 App.propTypes = { colors: PropType.array // PropType.array 这个规则是固定的,如果你要自定义的校验规则,请去看官方Api }

    ReactDOM.render ( , document.getElementById(‘root’) )

    1. <a name="F3uMT"></a>
    2. ### props校验的类型有哪些?如何自定义校验规则?
    3. - 第一类,常见的类型:array bool func number object string
    4. - 第二类。React元素类型:element
    5. - 第三类。必填项isReqyured
    6. - 第四类。特点结构的对象:shape({})
    7. - 这里只是我们最常见的类型,还有很多的类型。请去查看官方的文档,官方有详细的介绍和说明
    8. > 接下来,我们通过一个案例去演示一下,这个东西的使用
    9. > 需求如下:![image.png](https://cdn.nlark.com/yuque/0/2020/png/1627571/1596950132613-20f58af5-f778-4673-8093-98e971f7b2cc.png#align=left&display=inline&height=149&margin=%5Bobject%20Object%5D&name=image.png&originHeight=149&originWidth=738&size=84787&status=done&style=none&width=738)
    10. ```javascript
    11. const App = (prop)=> {
    12. return (
    13. <div>
    14. <h1>prop校验:</h1>
    15. </div>
    16. )
    17. }
    18. App.propTypes = {
    19. a: PropTypes.number,
    20. fn:PropTypes.func.isRequired,
    21. tag:PropTypes.element,
    22. filter:PropTypes.shape({
    23. area:PropTypes.string,
    24. price:PropTypes.number
    25. })
    26. }

    props是由默认值的

    从业务出发,如果我们要使用一个分页组件怎么搞?,我们希望有一个默认的值默认一页显示多少条,使用起来,非常的简单

    1. const App = (prop)=> {
    2. return (
    3. <div>
    4. <h1>prop的默认值:{prop.pageSize}</h1>
    5. </div>
    6. )
    7. }
    8. App.defaultProps = {
    9. pageSize:10
    10. }

    三、理解生命周期

    所谓的声明周期特别好理解,无非就是某个阶段触发的一系列特殊的事件🐎。再vue中有13个钩子函数。在react中也是有生命钩子的,接下来,我们来看看,最常见的生命周期钩子函 下图是一个说明 image.png

    创建阶段的生命周期钩子

    image.png
    组件创建的时候触发的钩子,有主要的三个钩子函数

    1. 先执行,constructor
    2. 再执行 render
    3. 最后执行 componentDidMount
    • 在这些生命钩子中,我们能做什么呢?

    image.png
    重点:render的时候不能调用setState()原因如下:

    每次组件渲染都会触发render,因为setState

    更新阶段的生命周期钩子

    执行时机:setState()、 forceUpdate()、 组件接收到新的props的时候都会触发这个生命钩子

    image.png

    1. import React from 'react'
    2. import ReactDOM from 'react-dom'
    3. /*
    4. 组件生命周期
    5. */
    6. class App extends React.Component {
    7. constructor(props) {
    8. super(props)
    9. // 初始化state
    10. this.state = {
    11. count: 0
    12. }
    13. }
    14. // 打豆豆
    15. handleClick = () => {
    16. this.setState({
    17. count: this.state.count + 1
    18. })
    19. }
    20. render() {
    21. return (
    22. <div>
    23. <Counter count={this.state.count} />
    24. <button onClick={this.handleClick}>打豆豆</button>
    25. </div>
    26. )
    27. }
    28. }
    29. class Counter extends React.Component {
    30. render() {
    31. console.warn('--子组件--生命周期钩子函数: render')
    32. return <h1 id="title">统计豆豆被打的次数:{this.props.count}</h1>
    33. }
    34. // 注意:如果要调用 setState() 更新状态,必须要放在一个 if 条件中
    35. // 因为:如果直接调用 setState() 更新状态,也会导致递归更新!!!
    36. componentDidUpdate(prevProps) {
    37. console.warn('--子组件--生命周期钩子函数: componentDidUpdate')
    38. // 正确做法:
    39. // 做法:比较更新前后的props是否相同,来决定是否重新渲染组件
    40. console.log('上一次的props:', prevProps, ', 当前的props:', this.props)
    41. if (prevProps.count !== this.props.count) {
    42. // this.setState({})
    43. // 发送ajax请求的代码
    44. }
    45. // 错误演示!!!
    46. // this.setState({})
    47. // 获取DOM
    48. // const title = document.getElementById('title')
    49. // console.log(title.innerHTML)
    50. }
    51. }
    52. ReactDOM.render(<App />, document.getElementById('root'))

    销毁阶段的生命周期钩子

    销毁的时候就非常的简单了,这里就不缀述了 image.png

    1. import React from 'react'
    2. import ReactDOM from 'react-dom'
    3. /*
    4. 组件生命周期
    5. */
    6. class App extends React.Component {
    7. constructor(props) {
    8. super(props)
    9. // 初始化state
    10. this.state = {
    11. count: 0
    12. }
    13. }
    14. // 打豆豆
    15. handleClick = () => {
    16. this.setState({
    17. count: this.state.count + 1
    18. })
    19. }
    20. render() {
    21. return (
    22. <div>
    23. {this.state.count > 3 ? (
    24. <p>豆豆被打死了~</p>
    25. ) : (
    26. <Counter count={this.state.count} />
    27. )}
    28. <button onClick={this.handleClick}>打豆豆</button>
    29. </div>
    30. )
    31. }
    32. }
    33. class Counter extends React.Component {
    34. componentDidMount() {
    35. // 开启定时器
    36. this.timerId = setInterval(() => {
    37. console.log('定时器正在执行~')
    38. }, 500)
    39. }
    40. render() {
    41. return <h1>统计豆豆被打的次数:{this.props.count}</h1>
    42. }
    43. componentWillUnmount() {
    44. console.warn('生命周期钩子函数: componentWillUnmount')
    45. // 清理定时器
    46. clearInterval(this.timerId)
    47. }
    48. }
    49. ReactDOM.render(<App />, document.getElementById('root'))

    其它的生命周期钩子

    除了上述的三大类的生命周期钩子,我们还有一些不常见的,但是在业务上是有可能会遇到的生命周期钩子,其中最重要的是一个叫做 附上一个相对比较完整的钩子函数

    image.png

    四、有关于组件还有业务逻辑代码的高度封装

    如果存在某些组件需要复用,某些组件需要高度的封装,这个时候可以考虑采取使用如下的常见的两种方式去编写通用的组件还有通用的 复用什么?

    • state
    • 操作state的方法

    prop的几种常见的设计模式

    render-props 它可以把特定行为或功能封装成一个组件,提供给其他组件使用让其他组件拥有这样的能力

    1. 要实现这样的方式设计方式,首先我们需要使用 拿到公用的组件的状态state,在使用组件时,添加一个值为函数的prop,通过函数参数来获取需要被提取出来公共的状态

    image.png

    1. 如何渲染任意的ui呢?也非常的简单,有了数据直接渲染就好了

    image.png

    1. class Mouse extends React.Component {
    2. // 鼠标位置状态
    3. state = {
    4. x: 0,
    5. y: 0
    6. }
    7. // 监听鼠标移动事件
    8. componentDidMount(){
    9. window.addEventListener('mousemove',this.handleMouseMove)
    10. }
    11. handleMouseMove = e => {
    12. this.setState({
    13. x: e.clientX,
    14. y: e.clientY
    15. })
    16. }
    17. render(){
    18. // 向外界提供当前子组件里面的数据,重点,使用这个方法的返回值,就能渲染任意结构的ui了!秒啊,而且也为逻辑的操作都是内部实现的!完全解耦
    19. return this.props.render(this.state)
    20. }
    21. }
    22. class App extends React.Component {
    23. render() {
    24. return (
    25. <div>
    26. App
    27. <Mouse render={mouse => {
    28. return <p>X{mouse.x}Y{mouse.y}</p>
    29. }}/>
    30. </div>
    31. )
    32. }
    33. }
    34. ReactDOM.render(<App />,document.getElementById('root'))
    1. 优化注意事项
    • 我们一般使用children来代替redner属性名
    • 推荐把props添加上校验规则
    • 性能角度 ,组件销毁的时候要解绑事件

    image.png
    image.png
    image.png

    1. class Mouse extends React.Component {
    2. // 鼠标位置状态
    3. state = {
    4. x: 0,
    5. y: 0
    6. }
    7. // 监听鼠标移动事件
    8. componentDidMount(){
    9. window.addEventListener('mousemove',this.handleMouseMove)
    10. }
    11. handleMouseMove = e => {
    12. this.setState({
    13. x: e.clientX,
    14. y: e.clientY
    15. })
    16. },
    17. componentWillUnmount(){
    18. window.removeEvenListener("mousemove",this.handleMouserMove)
    19. }
    20. render(){
    21. // 向外界提供当前子组件里面的数据,重点,使用这个方法的返回值,就能渲染任意结构的ui了!秒啊,而且也为逻辑的操作都是内部实现的!完全解耦
    22. return this.props.children(this.state)
    23. }
    24. }
    25. class App extends React.Component {
    26. render() {
    27. return (
    28. <div>
    29. App
    30. <Mouse children={mouse => {
    31. return <p>X{mouse.x}Y{mouse.y}</p>
    32. }}/>
    33. </div>
    34. )
    35. }
    36. }
    37. ReactDOM.render(<App />,document.getElementById('root'))

    高阶的组件封装

    HOC高阶组件实际上是一个工具,实现状态逻辑复用,采取包装模式 高阶组件(HOC、Higher-Order Component) 是一个函数,接收要包装的组件,返回增强后的组件

    核心技术

    • 接收要包装的组件,返回增强后的组件
    • image.png
    • 高级组件内部创建了一个类组件
    • image.png

      使用说明

    • 创建一个函数,名称约定以with开头
    • 指定函数参数,参数应该以大写字母开头
    • 在函数内部创建一个类组件,提供复用的状态逻辑代码,并返回
    • 在该组件中,渲染参数组件,同时将状态通过prop传递给参数组件
    • 调用该高阶组件,传入要增强的组件,通过返回值拿到增强后的组件,并将其渲染到页面

    包装函数

    1. // 定义一个函数,在函数内部创建一个相应类组件
    2. function withMouse(WrappedComponent) {
    3. // 该组件提供复用状态逻辑
    4. class Mouse extends React.Component {
    5. state = {
    6. x: 0,
    7. y: 0
    8. }
    9. // 事件的处理函数
    10. handleMouseMove = (e) => {
    11. this.setState({
    12. x: e.clientX,
    13. y: e.clientY
    14. })
    15. }
    16. // 当组件挂载的时候进行事件绑定
    17. componentDidMount() {
    18. window.addEventListener('mousemove', this.handleMouseMove)
    19. }
    20. // 当组件移除时候解绑事件
    21. componentWillUnmount() {
    22. window.removeEventListener('mousemove', this.handleMouseMove)
    23. }
    24. render() {
    25. // 在render函数里面返回传递过来的组件,把当前组件的状态设置进去
    26. return <WrappedComponent {...this.state} />
    27. }
    28. }
    29. return Mouse
    30. }

    加强组件

    1. function Position(props) {
    2. return (
    3. <p> // 这里的prop实际上就是我们的高阶函数里的state
    4. X:{props.x}
    5. Y:{props.y}
    6. </p>
    7. )
    8. }
    9. // 把position 组件来进行包装
    10. let MousePosition = withMouse(Position)
    11. class App extends React.Component {
    12. constructor(props) {
    13. super(props)
    14. }
    15. render() {
    16. return (
    17. <div>
    18. 高阶组件
    19. <MousePosition></MousePosition>
    20. </div>
    21. )
    22. }
    23. }

    优化和改进

    使用高阶组件存在如下的问题,

    1. 存在两个同名称的组件,没法区分(在dev-tools中)

    image.png
    为什么出现这个问题?image.png

    1. // 在render函数里面返回传递过来的组件,把当前组件的状态设置进去
    2. return <WrappedComponent {...this.state} />
    3. }
    4. }
    5. return Mouse // 你看都返回了Mouse

    解决方案,设置名字
    image.png
    这里的name就是组件的名称,注意啊,这个getDispalyName是不写在外面的!写在index中

    1. import React from 'react'
    2. import ReactDOM from 'react-dom'
    3. /*
    4. 高阶组件
    5. */
    6. import img from './images/cat.png'
    7. // 创建高阶组件
    8. function withMouse(WrappedComponent) {
    9. // 该组件提供复用的状态逻辑
    10. class Mouse extends React.Component {
    11. // 鼠标状态
    12. state = {
    13. x: 0,
    14. y: 0
    15. }
    16. handleMouseMove = e => {
    17. this.setState({
    18. x: e.clientX,
    19. y: e.clientY
    20. })
    21. }
    22. // 控制鼠标状态的逻辑
    23. componentDidMount() {
    24. window.addEventListener('mousemove', this.handleMouseMove)
    25. }
    26. componentWillUnmount() {
    27. window.removeEventListener('mousemove', this.handleMouseMove)
    28. }
    29. render() {
    30. return <WrappedComponent {...this.state} />
    31. }
    32. }
    33. // 设置displayName
    34. Mouse.displayName = `WithMouse${getDisplayName(WrappedComponent)}`
    35. return Mouse
    36. }
    37. function getDisplayName(WrappedComponent) {
    38. return WrappedComponent.displayName || WrappedComponent.name || 'Component'
    39. }
    40. // 用来测试高阶组件
    41. const Position = props => (
    42. <p>
    43. 鼠标当前位置:(x: {props.x}, y: {props.y})
    44. </p>
    45. )
    46. // 猫捉老鼠的组件:
    47. const Cat = props => (
    48. <img
    49. src={img}
    50. alt=""
    51. style={{
    52. position: 'absolute',
    53. top: props.y - 64,
    54. left: props.x - 64
    55. }}
    56. />
    57. )
    58. // 获取增强后的组件:
    59. const MousePosition = withMouse(Position)
    60. // 调用高阶组件来增强猫捉老鼠的组件:
    61. const MouseCat = withMouse(Cat)
    62. class App extends React.Component {
    63. render() {
    64. return (
    65. <div>
    66. <h1>高阶组件</h1>
    67. {/* 渲染增强后的组件 */}
    68. <MousePosition />
    69. <MouseCat />
    70. </div>
    71. )
    72. }
    73. }
    74. ReactDOM.render(<App />, document.getElementById('root'))
    1. 我们还有问题,就是prop传参的是也是一个问题
    • 问题:如果没有传递props,会导致props丢失问题
    • 解决方式: 渲染WrappedComponent时,将state和props一起传递给组件

    image.png

    1. import React from 'react'
    2. import ReactDOM from 'react-dom'
    3. /*
    4. 高阶组件
    5. */
    6. // 创建高阶组件
    7. function withMouse(WrappedComponent) {
    8. // 该组件提供复用的状态逻辑
    9. class Mouse extends React.Component {
    10. // 鼠标状态
    11. state = {
    12. x: 0,
    13. y: 0
    14. }
    15. handleMouseMove = e => {
    16. this.setState({
    17. x: e.clientX,
    18. y: e.clientY
    19. })
    20. }
    21. // 控制鼠标状态的逻辑
    22. componentDidMount() {
    23. window.addEventListener('mousemove', this.handleMouseMove)
    24. }
    25. componentWillUnmount() {
    26. window.removeEventListener('mousemove', this.handleMouseMove)
    27. }
    28. render() {
    29. console.log('Mouse:', this.props)
    30. return <WrappedComponent {...this.state} {...this.props} />
    31. }
    32. }
    33. // 设置displayName
    34. Mouse.displayName = `WithMouse${getDisplayName(WrappedComponent)}`
    35. return Mouse
    36. }
    37. function getDisplayName(WrappedComponent) {
    38. return WrappedComponent.displayName || WrappedComponent.name || 'Component'
    39. }
    40. // 用来测试高阶组件
    41. const Position = props => {
    42. console.log('Position:', props)
    43. return (
    44. <p>
    45. 鼠标当前位置:(x: {props.x}, y: {props.y})
    46. </p>
    47. )
    48. }
    49. // 获取增强后的组件:
    50. const MousePosition = withMouse(Position)
    51. class App extends React.Component {
    52. render() {
    53. return (
    54. <div>
    55. <h1>高阶组件</h1>
    56. <MousePosition a="1" />
    57. </div>
    58. )
    59. }
    60. }
    61. ReactDOM.render(<App />, document.getElementById('root'))

    总结

    • 组件通讯是构建React应用必不可少的一环
    • props的灵活性让组件更加强大
    • 状态提升是React组件的常用模式
    • 组件生命周期有助于理解组件的运行过程
    • 钩子函数让开发者可以在特定的时机执行某些功能
    • render props 模式和高阶组件都可以实现组件状态逻辑的复用
    • 组件极简模型: (state,props) => UI

    关于部分的性能优化问题

    我们可以通过一个特殊的生命周期函数,解决render多次非必要渲染所带来的性能问题,

    shoulCompentUpadta(){}
    如果这个函数返回的是fasle表示不会调用render函数进行页面的重新渲染,这个函数有两个参数
    上一个的prop,最新的prop,我们只需要对比两个是不是一样就好了,不一样就渲染,一样就不渲染

    目前这个东西,在React的更高版本中,好像是不能用了,于是还有另外的技术手段来解决这个问题

    集成axios

    1. 安装都非常好

      1. npm install -save axios
    2. 使用的时候也非常的简单,直接import的时候就可以了 ```javascript

    improt axios from ‘axios’ componentDitMount(){ axios.get(‘www.baidu.com’).then( (res) => { ….在这里,实际上你就拿到了res数据,然后就可以使用setData的方式进行一系列的处理 }).catch() } // 当然了,你也可以是哟async awite来处理 ```

    react动画到底怎么搞?

    特效非常的简单,你可以使用css3提供的一些库,然后通过react中的state设置一个变量,条件性改变的这个css类名就好了

    但是~,拿来主义不香吗?啊?!