Skip to content

Vue SDK

Official Vue 3 component for CaptchaLa CAPTCHA — published as @captcha-la/vue.

Live demo

📦

demo-v1.captcha.la/vue — runnable demo with all four product modes. Source: Captcha-La/vue-example.

Install

bash
npm install @captcha-la/vue
# or
yarn add @captcha-la/vue
# or
pnpm add @captcha-la/vue

Peer dependency: vue@^3.2.0.

Quick start

vue
<template>
  <Captchala
    app-key="your-app-key"
    product="popup"
    @success="handleSuccess"
    @error="handleError"
  />
</template>

<script setup>
import { Captchala } from '@captcha-la/vue'

function handleSuccess(result) {
  // Send result.token to your server for validation.
  console.log('pass_token:', result.token)
}

function handleError(error) {
  console.error('verification failed:', error)
}
</script>

Props

PropTypeDefaultDescription
appKeystringrequiredCaptchaLa application key
serverTokenstring-One-time, server-issued challenge token. Required when the app has server_token_required=true.
product'popup' | 'float' | 'embed' | 'bind''popup'Display mode
actionstring'default'Action identifier (e.g. login, register, checkout)
langstring'zh-CN'Language code (zh-CN, en, ja, …)
bindTostring | HTMLElement-Element selector or node to bind to (only for product="bind")

Events

EventPayloadDescription
success{ token, type, action }Verification succeeded
errorerrorVerification failed
closeCAPTCHA closed
readyCAPTCHA ready

Methods (via ref)

vue
<template>
  <Captchala ref="captchaRef" app-key="your-app-key" />
  <button @click="captchaRef?.verify()">Verify</button>
</template>

<script setup>
import { ref } from 'vue'
const captchaRef = ref()
</script>
MethodDescription
verify()Trigger verification
reset()Reset CAPTCHA state
destroy()Destroy the instance
bindTo(selector)Bind to element (for bind mode)
setLang(lang)Switch language in place

Production: serverToken mode

For high-value flows (login, register, payment) we recommend the server-issued token flow. Your backend mints a one-time server_token (5-minute TTL) via POST /v1/server/challenge/issue and hands it to the browser:

vue
<template>
  <Captchala
    v-if="serverToken"
    :server-token="serverToken"
    app-key="pk_your_public_app_key"
    action="login"
    @success="onSuccess"
  />
</template>

<script setup>
import { ref, onMounted } from 'vue'
import { Captchala } from '@captcha-la/vue'

const serverToken = ref()

onMounted(async () => {
  const r = await fetch('/api/captcha-token')   // your own backend
  serverToken.value = (await r.json()).server_token
})

function onSuccess(result) {
  console.log('pass_token:', result.token)
}
</script>

See API Reference for the full backend contract.

MIT-licensed examples · CaptchaLa is operated independently