Skip to content

Instantly share code, notes, and snippets.

@hypeJunction
Created July 4, 2019 22:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hypeJunction/81acdb5f43bb1f051a44e50a9409b037 to your computer and use it in GitHub Desktop.
Save hypeJunction/81acdb5f43bb1f051a44e50a9409b037 to your computer and use it in GitHub Desktop.
Vue reCaptcha component
<template>
<div
ref="recaptcha"
:data-sitekey="$recaptcha.siteKey"
:data-theme="theme"
:data-size="size"
></div>
</template>
<script>
export default {
model: {
event: 'input',
prop: 'value',
},
data () {
return {
widgetId: null,
isVerified: false,
};
},
props: {
value: {
type: String,
},
theme: {
type: String,
default: 'light',
},
size: {
type: String,
default: 'normal',
},
},
mounted () {
this.$nextTick(() => {
this.$recaptcha.load().then((recaptcha) => {
this.widgetId = recaptcha.render(this.$refs.recaptcha, {
callback: this.onSuccess,
expiredCallback: this.onExpire,
errorCallback: this.onError,
});
});
});
},
methods: {
onSuccess (response) {
this.$emit('input', response);
},
onExpire () {
this.$emit('expire');
this.reset();
},
onError (error) {
this.$emit('error', error);
this.reset();
},
/**
* Reset ReCaptcha programmatically
*
* @public
*/
reset () {
this.$emit('reset');
this.$emit('input', undefined);
this.$recaptcha.load().then((recaptcha) => {
recaptcha.reset(this.widgetId);
});
},
},
};
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment