Skip to content

Instantly share code, notes, and snippets.

@itslukej
Created May 1, 2021 18:29
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 itslukej/1cae1d611c03bbf6b701469eac3c695c to your computer and use it in GitHub Desktop.
Save itslukej/1cae1d611c03bbf6b701469eac3c695c to your computer and use it in GitHub Desktop.
hCaptcha vue but better
<template>
<div ref="container"></div>
</template>
<script>
export default {
data() {
return { id: null };
},
mounted() {
this.id = window.hcaptcha.render(this.$refs.container, {
sitekey: this.$env.HCAPTCHA_SITE_KEY,
theme: 'dark',
size: 'invisible',
callback: this.callback,
'expired-callback': this.error,
'chalexpired-callback': this.error,
'close-callback': this.error,
'error-callback': this.error
});
},
methods: {
getResponse() {
window.hcaptcha.execute(this.id);
return new Promise((resolve, reject) => {
this.$once('complete', () => {
resolve(window.hcaptcha.getResponse(this.id));
});
this.$once('error', reject);
});
},
callback() {
this.$emit('complete');
},
error() {
this.$emit('error');
}
}
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment