[](https://www.npmjs.com/package/vue-recaptcha-v3) [](https://www.npmjs.com/package/vue-recaptcha-v3)
npm install vue-recaptcha-v3A simple and easy to use reCAPTCHA (v3 only) library for Vue based on reCAPTCHA-v3.
The latest version of this package supports Vue 3! See here for Vue 2 usage.
bash
$ npm install vue-recaptcha-v3
`With Yarn:
`bash
$ yarn add vue-recaptcha-v3
`
Prerequisites
To use this package you only need a valid site key for your domain, which you can easily get here.Usage
`javascript
import Vue from 'vue'
import { VueReCaptcha } from 'vue-recaptcha-v3'// For more options see below
Vue.use(VueReCaptcha, { siteKey: '' })
new Vue({
methods: {
async recaptcha() {
// (optional) Wait until recaptcha has been loaded.
await this.$recaptchaLoaded()
// Execute reCAPTCHA with action "login".
const token = await this.$recaptcha('login')
// Do stuff with the received token.
}
},
template: ''
})
`$3
`js
import { createApp } from 'vue'
import { VueReCaptcha, useReCaptcha } from 'vue-recaptcha-v3'const component = {
setup() {
const { executeRecaptcha, recaptchaLoaded } = useReCaptcha()
const recaptcha = async () => {
// (optional) Wait until recaptcha has been loaded.
await recaptchaLoaded()
// Execute reCAPTCHA with action "login".
const token = await executeRecaptcha('login')
// Do stuff with the received token.
}
return {
recaptcha
}
},
template: ''
}
createApp(component)
.use(VueReCaptcha, { siteKey: '' })
`$3
To get type suggestions for instance variables (this is not needed for composition API), create a new file called shims-vue-recaptcha-v3.d.ts and put the following inside it:
`ts
import { ReCaptchaInstance } from 'recaptcha-v3'declare module '@vue/runtime-core' {
interface ComponentCustomProperties {
$recaptcha: (action: string) => Promise
$recaptchaLoaded: () => Promise
$recaptchaInstance: ReCaptchaInstance
}
}
`Options
This plugin offers optional options to configure the behavior of some parts.Available options:
|Name|Description|Type|Default value
|----|-----------|----|-------------
|siteKey|The site key for your domain from Google.|string|none
|loaderOptions|Optional options for the recaptcha-v3 loader. The available options are described here.|object|
null$3
To use the options just pass an object to the Vue.use(...) method. For example:
`javascript
import Vue from 'vue'
import { VueReCaptcha } from 'vue-recaptcha-v3'Vue.use(VueReCaptcha, {
siteKey: '',
loaderOptions: {
useRecaptchaNet: true
}
})
`Advanced usage
Some topics which are not commonly used, but required in some cases.$3
In some cases it's necessary to interact with the reCAPTCHA-v3 instance, which provides more control over reCAPTCHA.
`javascript
const recaptcha = this.$recaptchaInstance// Hide reCAPTCHA badge:
recaptcha.hideBadge()
// Show reCAPTCHA badge:
recaptcha.showBadge()
``