@[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
})
};
正确代码
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,
})
};