小编Swa*_*eti的帖子

在reactJs中settimeout函数内的事件数据为空

我有一个反应功能

<button onClick={(e) => this.playVideo(e, name)}>
Run Code Online (Sandbox Code Playgroud)

尝试了两种选择

playVideo(event, name) {
    console.log(event, 'event details');
    setTimeout(function () {
      console.log(event, 'event details inside timeout'); 
    }, 1500)
}
Run Code Online (Sandbox Code Playgroud)
playVideo(event, name) {
    console.log(event, 'event details');
    setTimeout(function (event) {
      console.log(event, 'event details inside timeout'); 
    }, 1500)
}
Run Code Online (Sandbox Code Playgroud)

在上面的代码中,初始事件按预期工作,但我需要 settimout 中的事件数据,因为我必须根据事件加载一些 js 文件,但 settimeout 函数中的事件数据始终为空。

我也尝试过onClickCapture但仍然没有运气

<button onClickCapture={(e) => this.playVideo(e, name)}>
Run Code Online (Sandbox Code Playgroud)

javascript settimeout reactjs

3
推荐指数
1
解决办法
1649
查看次数

标签 统计

javascript ×1

reactjs ×1

settimeout ×1