Home

Awesome

vue-recaptcha

devDependencies Status peerDependencies Status CircleCI npm version npm downloads

<a href="https://www.buymeacoffee.com/4bLIeMVjZ" target="_blank"><img src="https://www.buymeacoffee.com/assets/img/custom_images/orange_img.png" alt="Buy Me A Coffee" style="height: auto !important;width: auto !important;" ></a>

Description

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.

reCAPTCHA V3

Notice: This project currently not supporting reCAPTCHA v3.

<!-- TOC --> <!-- /TOC -->

Install

NPM

$ npm install --save vue-recaptcha

Yarn

$ yarn add vue-recaptcha

CDN

<!-- Make sure you load the vue-demi first -->
<script src="https://unpkg.com/vue-demi@0.12.1/lib/index.iife.js"></script>

<!-- Then load vue-recaptcha -->
<script src="https://unpkg.com/vue-recaptcha@^2/dist/vue-recaptcha.js"></script>
<!-- Minify -->
<script src="https://unpkg.com/vue-recaptcha@^2/dist/vue-recaptcha.min.js"></script>

Usage

Get started

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>

Manually call challenge

<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>

Bind Challenge to Button

<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

API

Props

The following props will only work when loadRecaptchaScript is set as true

For more information, please reference to ReCAPTCHA document and Invisible ReCAPTCHA document.

Methods

Events

FAQ

What is "ReCAPTCHA couldn't find user-provided function: vueRecaptchaApiLoaded"?

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.

How to test vue-recaptcha?

You can mock window.grecaptcha to bypass google's recaptcha. Here is an example which work with jest.

How about an e2e testing (or integration testing)?

Please reference to recaptcha's FAQ.

Manually load <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.