Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot get the camera reference #18

Open
NathanAP opened this issue Mar 6, 2023 · 3 comments
Open

Cannot get the camera reference #18

NathanAP opened this issue Mar 6, 2023 · 3 comments

Comments

@NathanAP
Copy link

NathanAP commented Mar 6, 2023

Hello!

I'm trying to use this component to capture images, but when I try to do this:

<script setup>
import { ref } from "vue";

const camera = ref(null);

async function capture() {
  console.log("Click");
}
</script>

<template>
  <camera autoplay ref="camera" />
  <v-btn @click="capture">Snapshot!</v-btn>
</template>

I keep getting this warning:

image

Am I doing something wrong?

@BastiaanJansen
Copy link
Owner

BastiaanJansen commented Mar 6, 2023

Hello,

Since you are using the setup tag, refs can only be used in onMounted like so:

<script setup> import { ref } from "vue"; const camera = ref(null); onMounted(() => { // use ref }) async function capture() { console.log("Click"); } </script>

Edit: apparently code blocks do not work on mobile...

@NathanAP
Copy link
Author

NathanAP commented Mar 6, 2023

I tried

<script setup>
import { onMounted, ref } from "vue";

let camera

async function capture() {
  console.log("Click");
}

onMounted(() => {
   camera = ref()
})
</script>

<template>
  <camera autoplay ref="camera" />
  <v-btn @click="capture">Snapshot!</v-btn>
</template>

but I'm still getting the warning. Actually it seems that everytime I use ref="myVariable" it throws that warning and the camera won't show, even if my const camera = ref(null) is not present.

Edit: I'm not expert or anything, but maybe a v-model could be a good way to make this work?

@hector-romero
Copy link

hector-romero commented Jun 26, 2024

I've found myself with this same issue and it apparently lies in having the same name as the component for the reference, so simply changing the ref name worked for me:

<script setup>
import { ref } from "vue";

const cameraObject = ref(null);

async function capture() {
   cameraObject.value.snapshot...
  console.log("Click");
}
</script>

<template>
  <camera autoplay ref="cameraObject" />
  <v-btn @click="capture">Snapshot!</v-btn>
</template>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants