vue-turnstile is a Vue 3 component library that simplifies the integration of Cloudflare Turnstile, a CAPTCHA alternative, into Vue applications. It provides a declarative `VueTurnstile` component that handles the underlying Turnstile API interactions, script loading, and token management. The current stable version is 1.0.11, suggesting a mature library actively maintained for Vue 3 environments. While a specific release cadence isn't published, the `1.0.x` versioning implies ongoing maintenance and minor updates as needed. Key differentiators include its tight integration with Vue's reactivity system (e.g., `v-model` for token binding), support for various Turnstile customization options like theme, size, and language, and explicit methods for resetting and re-rendering the widget. It abstracts away the complexities of directly interacting with the Cloudflare Turnstile JavaScript API, making it easier for developers to implement bot protection.
npm install vue-turnstileVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to integrate the `VueTurnstile` component into a Vue 3 application, bind the generated token using `v-model`, and display the token. It also shows how to access component methods like `reset()` via a template ref.
Implement server-side validation for the Turnstile token immediately after form submission. Consider using the `reset-interval` prop to automatically refresh tokens if user interaction is expected to be lengthy.
Replace the placeholder `site-key` with your actual production site key from Cloudflare Turnstile dashboard.
Update your CSP to include `script-src 'self' 'unsafe-inline' https://challenges.cloudflare.com; frame-src 'self' https://challenges.cloudflare.com;` (adjusting for your specific policy).
<vue-turnstile site-key="YOUR_SITE_KEY" v-model="token" />
Modify your Content Security Policy (CSP) to permit scripts and frames from `https://challenges.cloudflare.com`. For example, add `script-src https://challenges.cloudflare.com; frame-src https://challenges.cloudflare.com;` to your CSP headers or meta tag.
Ensure you have a `ref` attribute on the `VueTurnstile` component (e.g., `<vue-turnstile ref="turnstileWidget" ... />`) and access its methods using `this.$refs.turnstileWidget.reset()` after the component is mounted. Use optional chaining for robustness: `(this.$refs.turnstileWidget as any)?.reset()`.