我从滑块更改中获得了未定义的tmp,但没有单击按钮。两者应提供相同的输出,但事实并非如此。这是我的工作样子 Main.js
constructor(props) {
super(props);
this.state = {
tmp: 0,
}
this.accessTmp = this.accessTmp.bind(this)
}
accessTmp() {
let tst = this.state.tmp
alert(tst)
}
render() {
return(
<div>
<CustomSlider onChange= {this.accessTmp} />
<Button onClick = {this.accessTmp} />
</div>
)
}
Slider.js
const handle = props => {
const { value, dragging, index, ...restProps } = props;
return (
<Tooltip
prefixCls="rc-slider-tooltip"
overlay={value}
visible={dragging}
placement="top"
key={index}
>
<Handle value={value} {...restProps} />
</Tooltip>
);
};
const Slider = props => {
return (
<div>
<div style={{ width: 300, margin: 30 }}>
<p>{this.props.title}</p>
<Slider min={0} max={10} defaultValue={5} onChange={props.onChange} handle={handle}/>
</div>
</div>
);
};
export default Slider;
每当我单击按钮0时都会发出警报。但是,当我移动滑块时,会得到Cannot read property ‘tmp’ of undefined