yaogengzhu / longfeng-manage-react

基于react + typescript + antd 开发的后台管理系统
0 stars 0 forks source link

react 中class组件自定义初始化props 数据 #2

Open yaogengzhu opened 4 years ago

yaogengzhu commented 4 years ago

在class组件中初始化props 数据


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