vue-recaptcha

Google ReCAPTCHA component for Vue.js

Github星跟踪图

vue-recaptcha

Greenkeeper badge
devDependencies Status
peerDependencies Status
CircleCI
npm version
npm downloads

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 2.0. If you need Vue 1.x support please reference to vue-v1.x.

reCAPTCHA V3

Notice: This project currently not supporting reCAPTCHA v3.

Install

NPM

$ 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

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.

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

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

Auto-load <script>

If loadRecaptchaScript props is set to true, vue-recaptcha will inject the required <script> tag. This means that manually placing the <script> tag is unneccessary.

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

<script>
  import VueRecaptcha from 'vue-recaptcha';
  export default {
    ...
    components: { VueRecaptcha }
  };
</script>

API

Props

  • sitekey (required)
    ReCAPTCHA site key
  • theme (optional)
    The color theme for reCAPTCHA
  • type (optional)
    The type of reCAPTCHA
  • size (optional)
    The size of reCAPTCHA
  • tabindex (optional)
    The tabindex of reCAPTCHA
  • badge (optional) (Invisible ReCAPTCHA only)
    Position of the reCAPTCHA badge
  • loadRecaptchaScript (optional)
    If loadRecaptchaScript is set to true, vue-recaptcha will inject the required <script> tag
    Default: false

The 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.com
  • recaptchaScriptId (optional)
    Set this to change the injected <script> id. This should only be changed if it conflicts with existing id
    Default: __RECAPTCHA_SCRIPT
  • language (optional)
    Set this to change the reCAPTCHA language if necessary, as described in ReCAPTCHA support
    Default: '' // user browser language by default
    Notice: It'll not work as you expecting when you change this props dynamicly. Since it's impossible to change the language without a full page reloading

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
  • error()
    Emit when reCAPTCHA encounters an error

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.

主要指标

概览
名称与所有者DanSnow/vue-recaptcha
主编程语言TypeScript
编程语言JavaScript (语言数: 5)
平台
许可证MIT License
所有者活动
创建于2016-02-02 08:51:03
推送于2025-06-09 19:46:19
最后一次提交2023-03-01 21:48:26
发布数23
最新版本名称v2.0.3 (发布于 )
第一版名称v0.0.1 (发布于 )
用户参与
星数890
关注者数8
派生数134
提交数2.6k
已启用问题?
问题数195
打开的问题数41
拉请求数1711
打开的拉请求数10
关闭的拉请求数257
项目设置
已启用Wiki?
已存档?
是复刻?
已锁定?
是镜像?
是私有?