【发布时间】:2019-04-14 14:28:47
【问题描述】:
我有两个兄弟组件WebcamStream 和CaptureArea,我想将WebcamStream 的引用作为CaptureArea 的属性传递,但是当我这样做时,它总是为空。如何解决这个问题?
class AppContent extends React.Component {
constructor(props) {
super(props);
this.videoTag = React.createRef();
}
render() {
return (
<div id="content">
<WebcamStream ref={this.videoTag}
width="300" height="300"
title="Real-time video stream from webcam"
id="video" />
<CaptureArea x="20" y="20" width="120"
height="120" color="white"
videoTag={this.videoTag.current}/>
</div>
);
}
}
我为什么需要这个: CaptureArea 在当前的 video 标签上生成临时画布,以从中获取 imageData。我使用 imageData 来解析二维码。
【问题讨论】: