npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

vue3-recaptcha-v2-spa

v2.0.19

Published

reCAPTCHA for Vue3 : CompositionAPI, Types

Downloads

14

Readme

vue3-recaptcha-v2

GitHub package.json version npm bundle size NPM

reCAPTCHA v2 for Vue3 and Nuxt3.

Installation

install the packge from yarn:

$ yarn add vue3-recaptcha-v2

In Vue3, add it to your main.ts file:

import { createApp } from "vue";
import App from "./App.vue";

import { install } from "vue3-recaptcha-v2";

createApp(App)
  .use(install, {
    sitekey: "YOUT_SITE_KEY",
    cnDomains: false, // Optional, If you use in China, set this value true
  })
  .mount("#app");

In Nuxt3, add it to your plugin folder:

The file name must contain the .client.

// <ProjectRoot>/plugins/recaptcha.client.ts
import { install } from "vue3-recaptcha-v2";

export default defineNuxtPlugin((nuxtApp) => {
  nuxtApp.vueApp.use(install, {
    sitekey: "YOUT_SITE_KEY",
    cnDomains: false,
  });
});

More detail about install options, you can check this Install Options

Usage

The components used are the same for Vue3 and Nuxt3. Only the installation is different.

For more information, including the props to change the language(hl option), check Component Options

<script setup lang="ts">
import { RecaptchaV2 } from "vue3-recaptcha-v2";

const handleWidgetId = (widgetId: number) => {
  console.log("Widget ID: ", widgetId);
};
const handleErrorCalback = () => {
  console.log("Error callback");
};
const handleExpiredCallback = () => {
  console.log("Expired callback");
};
const handleLoadCallback = (response: unknown) => {
  console.log("Load callback", response);
};
</script>

<template>
  <RecaptchaV2
    @widget-id="handleWidgetId"
    @error-callback="handleErrorCalback"
    @expired-callback="handleExpiredCallback"
    @load-callback="handleLoadCallback"
  />
</template>

Invisible widget

<script setup lang="ts">
import { RecaptchaV2, useRecaptcha } from "vue3-recaptcha-v2";

const { handleExecute } = useRecaptcha();

const handleWidgetId = (widgetId: number) => {
  console.log("Widget ID: ", widgetId);
  handleExecute(widgetId);
};
</script>

<template>
  <RecaptchaV2 @widget-id="handleWidgetId" size="invisible" />
</template>

Reset widget

Resets the reCAPTCHA widget.

<script setup lang="ts">
import { RecaptchaV2, useRecaptcha } from "vue3-recaptcha-v2";

const { handleReset } = useRecaptcha();

const handleWidgetId = (widgetId: number) => {
  console.log("Widget ID: ", widgetId);
  handleReset(widgetId);
};
</script>

<template>
  <RecaptchaV2 @widget-id="handleWidgetId" />
</template>

Get response widget

Gets the response for the reCAPTCHA widget.

<script setup lang="ts">
import { RecaptchaV2, useRecaptcha } from "vue3-recaptcha-v2";

const { handleGetResponse } = useRecaptcha();

const handleWidgetId = (widgetId: number) => {
  console.log("Widget ID: ", widgetId);
  handleGetResponse(widgetId);
};
</script>

<template>
  <RecaptchaV2 @widget-id="handleWidgetId" />
</template>

Options

Install Options

| Options | Type | Required | Description | | | ----------- | -------- | -------- | ------------------------------------------------------------------------------------------------------ | --- | | sitekey | string | true | recaptcha siteKey | | | cnDomains | string | | default is false. if you set true, script url is replace www.google.com with www.recaptcha.net | |

Component Options

Props

| Options | Type | Required | Description | | ---------- | ------------------------------------- | -------- | --------------------------------------------------------------------------------------------------------------- | | language | string | | recaptcha language, you can find code in language code | | theme | light | dark | | default is light, recaptcha theme | | tabindex | number | | default is 0, tabindex | | size | normal | comapact | invisible | | default is normal, recaptcha widget size |

emits

| Options | Type | Required | Description | | ------------------ | -------------------------- | -------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | widget-id | (value:number)=>void | | when recaptcha widget is created, return widgetId | | error-callback | ()=>void | | The name of your callback function, executed when reCAPTCHA encounters an error (usually network connectivity) and cannot continue until connectivity is restored. If you specify a function here, you are responsible for informing the user that they should retry. | | expired-callback | ()=>void | | The name of your callback function, executed when the reCAPTCHA response expires and the user needs to re-verify. | | load-callback | (response:unknown)=>void | | The name of your callback function, executed when the user submits a successful response. The g-recaptcha-response token is passed to your callback. |