In my @vue3/cli project, I am facing a straightforward problem that I can't seem to find a solution for.
I have two components within the same view hierarchy. One component displays webcam video in a video tag, while the other component contains an HTML5 canvas. My goal is to render a portion of the video on the canvas component, but I'm unsure how to send the video image from one component to the other.
Home -->
WebCam.vue
Canvas.vue
I attempted to send the video data from the WebCam component to the Canvas component using:
this.emitter.emit('cam-image', {
id:'video',
image: this.video
})
Despite using mitt for event emitting, this approach did not work as expected. The entire video tag is being logged in my console.
this.emitter.on("cam-image", data => {
console.log(data.image)
this.canvasContext.drawImage(
data.image,
0, 0,
300, 150,
0, 0, this.canvasWidth, this.canvasHeight
);
})
As an alternative, I considered accessing the refs from the Canvas component within the WebCam component to directly render the image from there.