【发布时间】:2019-10-29 06:31:26
【问题描述】:
https://www.npmjs.com/package/nouislider-react 无法将值插入滑块
class KeyboardSlider extends React.Component {
state = { ref: null };
changeByRef = () => {
const { ref } = this.state;
if (ref && ref.noUiSlider) {
ref.noUiSlider.set(20);
}
};
render() {
return (
<div>
<button onClick={this.changeByRef}>Change with ref</button>
<Nouislider
instanceRef={instance => {
if (instance && !ref) {
this.setState({ ref: instance });
}
}}
start={0}
range={{
min: 0,
max: 100
}}
/>
</div>
);
}
}
此代码不起作用会出错 第 665 行:'ref' 未定义 no-undef ..................................................... .....................................................
【问题讨论】:
-
我知道这是旧的,但你设法让它工作了吗?
标签: reactjs nouislider