我已经尝试了很多次在我的Vue 3项目中添加reCaptcha。如果有人知道如何在vue 3中添加reCaptcha,请帮助我。
我尝试安装了vue-reCaptcha npm包,但它没有起作用。我想添加“我不是机器人”的复选框。
我已经尝试了很多次在我的Vue 3项目中添加reCaptcha。如果有人知道如何在vue 3中添加reCaptcha,请帮助我。
我尝试安装了vue-reCaptcha npm包,但它没有起作用。我想添加“我不是机器人”的复选框。
按照以下步骤在Vue3应用程序中使用reCAPTCHA。
Using Yarn: "yarn add vue-recaptcha"
Using NPM: "npm i vue-recaptcha"
这是你可以跟随的代码片段。
<template>
<VueRecaptcha
:sitekey="siteKey"
:load-recaptcha-script="true"
@verify="handleSuccess"
@error="handleError"
></VueRecaptcha>
</template>
<script lang="ts">
import { computed, defineComponent } from 'vue';
import { VueRecaptcha } from 'vue-recaptcha';
export default defineComponent({
name: 'ReCaptcha',
components: {
VueRecaptcha
},
setup() {
const siteKey = computed(() => {
return 'yourSiteAPIKey';
});
const handleError = () => {
// Do some validation
};
const handleSuccess = (response: string) => {
// Do some validation
};
return {
handleSuccess,
handleError,
siteKey,
};
}
});
</script>
请前往文档了解有关您可以使用的属性和方法的更多信息:https://github.com/DanSnow/vue-recaptcha#readme
<VueRecaptcha
class="full-width"
:sitekey="siteKey"
:load-recaptcha-script="true"
@verify="handleSuccess"
@error="handleError"
>
<button type="submit"> Submit </button>
</VueRecaptcha>