Currently you are viewing v3 document of vue-recaptcha which is still in development

ChallengeV2 v2

Create invisible reCAPTCHA v2

Code
<script setup lang="ts">
import { RecaptchaV2State } from '#recaptcha'

const map = {
  [RecaptchaV2State.Init]: 'Click to Challenge',
  [RecaptchaV2State.Verified]: 'Verified',
  [RecaptchaV2State.Expired]: 'Expired',
  [RecaptchaV2State.Error]: 'Error',
}

const response = ref()
</script>

<template>
  <ChallengeV2 v-slot="{ state }" v-model="response">
    <PrimaryButton>{{ map[state] }}{{ response ? ` ${response.slice(0, 6)}...` : '' }}</PrimaryButton>
  </ChallengeV2>
</template>

Props

keytypedefaultdescription
asstring'div'What element to render
badge`'bottomright''bottomleft''inline'`
autoExecutebooleantrueShould vue-recaptcha execute challenge on click, if you set it to false you'll need to call the execute method in the slot

v-model

keytypedescription
modelValuestringThe reCAPTCHA response
widgetIdstringWidget id for reCAPTCHA checkbox

About modelValue

You can set modelValue to null or empty string to reset reCAPTCHA checkbox.

About the visible Badge for invisible reCAPTCHA

You should be able to see the reCAPTCHA badge in the bottom right corner of this page. It is a mark displayed by Google when you use invisible reCAPTCHA. You can add the following CSS code to hide it.

.grecaptcha-badge { visibility: hidden; }

Please note that, according to Google's requirements, you will need to explicitly state that you are using reCAPTCHA. For more information, you can refer to this link

Slots

default

This is the position that usually place a your submit button. When click on the content, ChallengeV2 will automatically execute the reCAPTCHA challenge by default

Slot API

interface SlotApi {
  /**
   * widget id
   */
  widgetId: WidgetID | undefined
  /**
   * reCAPTCHA state
   */
  state: RecaptchaV2State

  isError: boolean
  isExpired: boolean
  isVerified: boolean

  /**
   * reset reCAPTCHA
   */
  reset: () => void
  /**
   * execute challenge
   */
  execute: () => void
}

RecaptchaV2State

export enum RecaptchaV2State {
  Init = 'init',
  Verified = 'verified',
  Expired = 'expired',
  Error = 'error',
}