@[TOC]video组件找不到ref问题

遇到问题

在弹出层中显示视频,点击右上方关闭按钮是,总会报错(找不到pause),而且视频暂停了,里面的背景音乐却还在继续。弹出层是动态渲染的(数组循环渲染),打开不同视频弹出的总是第一个视频。

错误代码

scanVideo = () => {
if(this.refs.video != undefined){
this.refs.video.play();
}
this.setState({
videoScan: true,
})
};

closeVideoScan = () => {
this.refs.video.pause();
this.setState({
videoScan: false
})
};
video组件

正确代码

constructor(props){
super(props);
this.state = {
videoNum: ‘’,
}
}
scanVideo = (num) => {
if(this.video != undefined){
this.video.muted=true;
this.video.play();
}
this.setState({
videoScan: true,
videoNum: num,
})
};
video组件

相关文章:

  • 2022-02-08
  • 2022-01-02
  • 2022-12-23
  • 2022-12-23
  • 2021-05-24
  • 2021-11-25
  • 2021-12-26
  • 2021-05-21
猜你喜欢
  • 2021-04-14
  • 2022-12-23
  • 2021-09-25
  • 2021-07-20
  • 2022-12-23
  • 2021-05-15
  • 2021-06-28
相关资源
相似解决方案