Open yaogengzhu opened 4 years ago
import React from 'react'; interface IState { date: string } interface IProps { title: string } class Main extends React.Component<IProps, IState > { static defaultProps = { title: '您好' } constructor(props: IProps) { super(props) this.state = { date: '2020-02-09' } } render() { const { date } = this.state return ( <div> <p>{ date }</p> <p>{this.props.title}</p> </div> ) } } export default Main
在class组件中初始化props 数据