请问我的这个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);

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题