报错描述
点击按钮,触发
chargeFunc
函数,很简单的一个操作,却报了如下错误
报错内容如下
image.png解决办法
chargeFunc(){}
改成chargeFunc= (e) => {}
错误写法
class Operation extends React.PureComponent {
constructor(props) {
super(props);
this.state = {
file: "2112",
};
}
render() {
return (
<Fragment>
<Button key="submit" type="primary" onClick={this.chargeFunc}>
确定{" "}
</Button>
</Fragment>
);
}
chargeFunc() {
console.log("file为", this.state.file);
}
}
export default Operation;
正确写法
class Operation extends React.PureComponent {
constructor(props) {
super(props);
this.state = {
file: "2112",
};
}
render() {
return (
<Fragment>
<Button key="submit" type="primary" onClick={this.chargeFunc}>
确定{" "}
</Button>
</Fragment>
);
}
chargeFunc= (e) => {
console.log("file为",this.state.file);
}
}
export default Operation;
网友评论