Skip to content

Instantly share code, notes, and snippets.

@hypeJunction
Last active July 4, 2019 22:43
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/05ddb40d38da4e107ea73b097656d1d2 to your computer and use it in GitHub Desktop.
Save hypeJunction/05ddb40d38da4e107ea73b097656d1d2 to your computer and use it in GitHub Desktop.
Vue reCaptcha
export default {
install (Vue, { siteKey }) {
Vue.prototype.$recaptcha = {
siteKey,
load () {
return new Promise((resolve, reject) => {
if (typeof window.grecaptcha === 'undefined') {
const script = document.createElement('script');
script.src = 'https://www.google.com/recaptcha/api.js';
script.async = true;
script.defer = true;
script.onload = () => {
window.grecaptcha.ready(() => {
resolve(window.grecaptcha);
});
};
script.onerror = reject;
script.onabort = reject;
document.head.appendChild(script);
} else {
window.grecaptcha.ready(() => {
resolve(window.grecaptcha);
});
}
});
},
};
Vue.component('vue-recaptcha', () => import('./VueRecaptcha.vue'));
},
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment