简体   繁体   English

使用 react-input-slider 时 React event.target.value 返回 undefined

[英]React event.target.value returns undefined when using react-input-slider

I am using the react-input-slider in my codebase currently and am having errors when trying to seek using the slider.我目前在我的代码库中使用 react-input-slider,并且在尝试使用 slider 进行搜索时遇到错误。 It can be found here: https://www.npmjs.com/package/react-input-slider可以在这里找到: https://www.npmjs.com/package/react-input-slider

I am using it like this:我这样使用它:

import Slider from 'react-input-slider';

<Slider
 className="clickable-seek-bar"
 axis="x"
 type="range"
 xmin={0}
 xmax={0.999999}
 xstep={0.1}
 x={this.state.played}
 onDragStart={this.handleSeekMouseDown}
 onDragEnd={this.handleSeekMouseUp}
 onChange={this.handleSeekChange}
/>

These are the functions I have:这些是我拥有的功能:

handleSeekMouseDown(e) {
 this.setState({ ...this.state, seeking: true });
}

handleSeekChange(e) {
 this.setState({ ...this.state, played: parseFloat(e.target.value) });
}

handleSeekMouseUp(e) {
 console.log("TEST", e.target.value);
 this.player.seekTo(parseFloat(e.target.value));
 this.setState({ ...this.state, seeking: false });
}

Whenever I click on the bar, I get an error saying:每当我单击该栏时,都会收到一条错误消息:

(index):33 Uncaught TypeError: Cannot read property 'value' of undefined

I am not sure what is causing this.我不确定是什么原因造成的。 event.target.value is returning undefined for some reason. event.target.value 由于某种原因返回未定义。

You need to pass e as a parameter when you call the event handler function.调用事件处理程序 function 时需要将 e 作为参数传递。 It'd be something like this会是这样的

import Slider from 'react-input-slider';

<Slider
 className="clickable-seek-bar"
 axis="x"
 type="range"
 xmin={0}
 xmax={0.999999}
 xstep={0.1}
 x={this.state.played}
 onDragStart={this.handleSeekMouseDown}
 onDragEnd={this.handleSeekMouseUp}
 onChange={ e => this.handleSeekChange(e)}
/>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM