Notice: The document on github is always reference to master branch. For stable version, please read the document at NPM.
Google ReCAPTCHA component for vue. If you like this package, please leave a star on github.
This version is for Vue 3 and 2.
Notice: This project currently not supporting reCAPTCHA v3.
$ npm install --save vue-recaptcha
$ yarn add vue-recaptcha
<script src="https://unpkg.com/vue-demi@0.12.1/lib/index.iife.js"></script>
<script src="https://unpkg.com/vue-recaptcha@^2/dist/vue-recaptcha.js"></script>
<script src="https://unpkg.com/vue-recaptcha@^2/dist/vue-recaptcha.min.js"></script>
Include vue-recaptcha in your app.
<template>
<vue-recaptcha sitekey="Your key here"></vue-recaptcha>
</template>
<script>
import { VueRecaptcha } from 'vue-recaptcha';
export default {
...
components: { VueRecaptcha }
};
</script>
<template>
<vue-recaptcha ref="recaptcha" sitekey="Your key here" />
</template>
<script>
import { VueRecaptcha } from 'vue-recaptcha';
export default {
components: { VueRecaptcha }
methods: {
onEvent() {
// when you need a reCAPTCHA challenge
this.$refs.recaptcha.execute();
}
}
};
</script>
<template>
<vue-recaptcha sitekey="Your key here">
<button>Click me</button>
</vue-recaptcha>
</template>
<script>
import { VueRecaptcha } from 'vue-recaptcha';
export default {
...
components: { VueRecaptcha }
};
</script>
Notice: You could only place ONE element as vue-recaptcha child.
For more information, please reference to example
sitekey (required) –
ReCAPTCHA site keytheme (optional) –
The color theme for reCAPTCHAtype (optional) –
The type of reCAPTCHAsize (optional) –
The size of reCAPTCHAtabindex (optional) –
The tabindex of reCAPTCHAbadge (optional) (Invisible ReCAPTCHA only) –
Position of the reCAPTCHA badgeloadRecaptchaScript (optional) –
If loadRecaptchaScript when set this to true, vue-recaptcha will inject the required <script> tag automatically.
Disable this by setting this to false, and you need to inject the <script> tag manually. Please refer to Manually load script for more information.
Default: trueThe following props will only work when loadRecaptchaScript is set as true
recaptchaHost (optional) –
Set this to change the reCAPTCHA domain if neccessary, as described in ReCAPTCHA support
Default: www.google.comrecaptchaScriptId (optional) –
Set this to change the injected <script> id. This should only be changed if it conflicts with existing id
Default: __RECAPTCHA_SCRIPTlanguage (optional) –
Set this to change the reCAPTCHA language if necessary, as described in ReCAPTCHA support
Default: '' // user browser language by defaultFor more information, please reference to ReCAPTCHA document and Invisible ReCAPTCHA document.
reset –
Reset reCAPTCHA instanceexecute –
Invoke reCAPTCHA challengeverify(response) –
Emit on reCAPTCHA verified
response is the successful reCAPTCHA responseexpired() –
Emit on reCAPTCHA expiredrender(id) –
Emit on reCAPTCHA mounted on DOM
id is the widget id of the componenterror() –
Emit when reCAPTCHA encounters an errorhtml
<vue-recaptcha
:siteKey="siteKey"
@verify="verifyMethod"
@expired="expiredMethod"
@render="renderMethod"
@error="errorMethod">
</vue-recaptcha>
It's because google's recaptcha have been loaded before your app. You can simply ignore it because vue-recaptcha can still detect and render recaptcha. If you care about this, try to move the script tag of recatpcha after to your app.
You can mock window.grecaptcha to bypass google's recaptcha.
Here is an example which work with jest.
Please reference to recaptcha's FAQ.
<script>Place this in head to load reCAPTCHA:
<script src="https://www.google.com/recaptcha/api.js?onload=vueRecaptchaApiLoaded&render=explicit" async defer>
</script>
With `onload` callback, it will notify us when the api is ready for use.
$ claude mcp add vue-recaptcha \
-- python -m otcore.mcp_server <graph>