📜  在 React 类组件中实现状态生命周期 - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:02:04.800000             🧑  作者: Mango

代码示例1
class Example extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      count: 0
    };
  }

  componentDidMount() {
    document.title = `You clicked ${this.state.count} times`;
  }
  componentDidUpdate() {
    document.title = `You clicked ${this.state.count} times`;
  }

  render() {
    return (
      

You clicked {this.state.count} times

); } }