I’m using Vue 3 for my project and need to get use a ref from a third-party ReCaptcha package during the submission of a form. The code does not recognize the ref name since I did not personally create this ref:
JavaScript
x
6
1
async function submitContact() {
2
const token = await mrecaptcha.getToken();
3
4
5
'mrecaptcha' is not defined.
6
It’s used in the template like this:
JavaScript
1
2
1
<recaptcha v-if="isClient" ref="mrecaptcha" :site-key="siteKey" />
2
Usage can be found in the docs for this package here: https://www.npmjs.com/package/@appsbd/vue3-recaptcha
Advertisement
Answer
You need to create a ref
in the script
to get the element reference of recaptcha
.
JavaScript
1
2
1
const mrecaptcha = ref(null)
2
Ex:
JavaScript
1
8
1
<script setup>
2
const mrecaptcha = ref(null)
3
4
onMounted(() => {
5
console.log(mrecaptcha)
6
})
7
</script>
8