3.0.0-alpha.6 • Published 9 months ago

vue-recaptcha v3.0.0-alpha.6

Weekly downloads
36,258
License
MIT
Repository
github
Last release
9 months ago

vue-recaptcha

Greenkeeper badge devDependencies Status peerDependencies Status CircleCI npm version npm downloads

Description

Google ReCAPTCHA component for vue. If you like this package, please leave a star on github.

This version is for Vue 2.0. If you need Vue 1.x support please reference to vue-v1.x.

Install

NPM (Recommend)

$ npm install --save vue-recaptcha

CDN

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

Usage

Get started

import Vue from 'vue'
import VueRecaptcha from 'vue-recaptcha'

Vue.use(VueRecaptcha)

If you are still using commonjs or load the vue-recaptcha from CDN, you'll need:

// commonjs
const Vue = require('vue')
const VueRecaptcha = require('VueRecaptcha').default
Vue.use(VueRecaptcha)
// CDN
Vue.use(VueRecaptcha.default)

Then include vue-recaptcha in your app.

<template>
  <vue-recaptcha sitekey="Your key here"></vue-recaptcha>
</template>

<script>
  export default {
    ...
  };
</script>

Bind Challenge to Button

<template>
  <vue-recaptcha sitekey="Your key here">
    <button>Click me</button>
  </vue-recaptcha>
</template>

<script>
  export default {
    ...
  };
</script>

Notice: You could only place one element as vue-recaptcha child.

For more information, please reference to example

Configure Language

By default recaptcha will automatically detect user's language. If you need to force the component to render in another language, you can configure it like this:

import Vue from 'vue'
import VueRecaptcha from 'vue-recaptcha'

Vue.use(VueRecaptcha, {language: 'en'})

Please notice that it's not possible to change recaptcha language without page reload.

Advanced Usage

You can directly import VueRecaptcha component like this:

<template>
  <vue-recaptcha sitekey="Your key here"></vue-recaptcha>
</template>
<script>
  import {VueRecaptcha} from 'vue-recaptcha'
  export default {
    components: {VueRecaptcha}
  }
</script>

This will disable the "autoload the recaptcha api" if you doesn't install the VueRecaptcha plugin.

API

Props

  • sitekey (required)
    ReCAPTCHA site key
  • theme (optional)
    The color theme for reCAPTCHA, default is light, available values: dark, light
  • size (optional)
    The size of reCAPTCHA, default is normal, available values: normal, compact, invisible
  • tabindex (optional)
    The tabindex of reCAPTCHA, default is 0
  • badge (optional) (Invisible ReCAPTCHA only)
    Position of the reCAPTCHA badge, default is bottomright, available values: bottomright, bottomleft, inline

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

Methods

  • reset
    Reset reCAPTCHA instance
  • execute
    Invoke reCAPTCHA challenge

Events

  • verify(response) Emit on reCAPTCHA verified response is the successful reCAPTCHA response
  • expired() Emit on reCAPTCHA expired
  • render(id) Emit on reCAPTCHA mounted on DOM id is the widget id of the component

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 refernece to recaptcha's faq.

3.0.0-alpha.6

9 months ago

3.0.0-alpha.1

1 year ago

3.0.0-alpha.3

1 year ago

3.0.0-alpha.2

1 year ago

3.0.0-alpha.5

12 months ago

3.0.0-alpha.4

1 year ago

2.0.3

2 years ago

2.0.2

2 years ago

2.0.1

2 years ago

2.0.0

2 years ago

1.3.0

4 years ago

1.2.0

5 years ago

2.0.0-beta

5 years ago

1.1.1

6 years ago

1.1.0

6 years ago

1.0.0

6 years ago

0.4.0

7 years ago

0.3.3

7 years ago

0.3.2

7 years ago

0.3.1

7 years ago

0.3.0

7 years ago

0.2.1

7 years ago

0.2.0

7 years ago

0.1.4

7 years ago

0.1.3

8 years ago

0.1.2

8 years ago

0.1.1

8 years ago

0.1.0

8 years ago

0.0.2

8 years ago

0.0.1

8 years ago