constructor()
- 初始化state
- 创建ref
import React, {
Component } from 'react';
class demo extends Component {
constructor(props) {
super(props);
this.state = {
dataSource: []
}
this.xxRef = React.createRef();
}
render() {
const {
name
} = this.state;
return(<div></div>)
}
}
export default demo;
componentDidMount()
- 组件已经被渲染到 DOM 中后运行
- 一般用于页面初始化的接口调用
import React from 'react';
import * as http from './http'; // 封装好的httpServer
class demo