Google Recaptcha in VueJS

I Nyoman Jyotisa
3 min readMar 25, 2023

If you’ve ever filled out a form online, chances are you’ve encountered Google’s reCAPTCHA. This security feature helps prevent automated bots from spamming websites by requiring users to complete a challenge that only humans can do, such as selecting images that match a certain description or typing in distorted text. In this story, we’ll walk through how to add reCAPTCHA to a VueJS form using the Vue Recaptcha component.

Before we begin, you’ll need to have a Google account and generate a site key and secret key for your domain. You can do this by visiting the Google reCAPTCHA admin console and following the instructions. Once you have your keys, we can start setting up our VueJS project.

First, let’s install the Vue Recaptcha package via npm.

npm install vue-recaptcha

Next, let’s import the component and register it in our Vue instance.

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

Vue.component('vue-recaptcha', VueRecaptcha)

Now we can use the vue-recaptcha component in our template.

<template>
<div>
<form @submit.prevent="submitForm">
<label>
Name:
<input type="text" v-model="name">
</label>
<label>
Email:
<input type="email" v-model="email">
</label>…

--

--

I Nyoman Jyotisa
I Nyoman Jyotisa

Written by I Nyoman Jyotisa

Web Developer at Osky Interactive Pty Ltd

Responses (1)