请问我的这个react组件的写法哪里错了,浏览器即时编译都是能运行正常的。

编译出错的代码

const Radio = antd.Radio;
const options = [
    {value: '1', label: '语文'},
    {value: '2', label: '数学'},
    {value: '3', label: '英语'}
];
class DryRadio extends React.Component
{
    state = {value: '2'};
    onChange = e => {
        this.setState({value: e.target.value});
    };
    render(){
        return (
            <div>
                <Radio.Group name="test" options={options} onChange={this.onChange} value={this.state.value}/>
            </div>
        );
    }
}

截屏2019-11-1210.25.55.png

下面这段代码就可以编译成功

class Test extends React.Component {
    render() {
        return (
            <h1>test</h1>
        );
    }
}
阅读 3.1k
4 个回答
constrcutor() {
  this.state = {value: '2'};
}
class DryRadio extends React.Component{
    constructor(props) {
        super(props); 
        this.state = {
            value: '2'
        }
    }
    onChange = e => {
        this.setState({value: e.target.value});
    };
    render(){
        return (
            <div>
                ...
            </div>
        );
    }
}
新手上路,请多包涵

class DryRadio extends Component {

state={value:'2'};

}
export default withRouter(DryRadio);

推荐问题