[英]Vue3 use ref from third party package in setup script
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.我正在为我的项目使用 Vue 3,并且需要在提交表单期间使用来自第三方 ReCaptcha package 的参考。 The code does not recognize the ref name since I did not personally create this ref:
该代码无法识别引用名称,因为我没有亲自创建此引用:
async function submitContact() {
const token = await mrecaptcha.getToken();
...
'mrecaptcha' is not defined.
It's used in the template like this:它在模板中使用如下:
<recaptcha v-if="isClient" ref="mrecaptcha" :site-key="siteKey" />
Usage can be found in the docs for this package here: https://www.npmjs.com/package/@appsbd/vue3-recaptcha用法可以在此 package 的文档中找到: https://www.npmjs.com/package/@appsbd/vue3-recaptcha
You need to create a ref
in the script
to get the element reference of recaptcha
.您需要在
script
中创建一个ref
以获取recaptcha
的元素引用。
const mrecaptcha = ref(null)
Ex:前任:
<script setup>
const mrecaptcha = ref(null)
onMounted(() => {
console.log(mrecaptcha)
})
</script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.