Skip to content

Instantly share code, notes, and snippets.

@Maxim-Kolmogorov
Created May 19, 2020 05:34
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save Maxim-Kolmogorov/1bfe3de25cc8a5270ed0a1417a8a3f81 to your computer and use it in GitHub Desktop.
The second implementation option for the article: https://kolmogorov.pro/integration_google_recaptcha_v3_in_site_on_vue_js
let reCaptcha = new Promise((resolve, reject) => {
const $script = document.createElement('script')
$script.src = 'https://www.google.com/recaptcha/api.js?render=ВАШ_КЛЮЧ'
resolve(document.head.appendChild($script));
setTimeout(() => reject(new Error("Google reCaptcha не инициализирована")), 3000);
});
reCaptcha
.then(
result => {
setTimeout(() => {
grecaptcha.ready(function() {
grecaptcha.execute('ВАШ_КЛЮЧ', {action: 'homepage'}).then(function(token) {
axios
.post('/functions/recaptcha.php', {
token: token
})
.catch(() => {
console.log('POST-запрос в API Google не был отправлен.');
})
});
});
}, 1000)
},
error => {
console.log(error);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment