小编Ahm*_*et 的帖子

recaptcha在Vue组件中不起作用。当未加载grecaptcha时,给grecaptcha.render不是一个函数

如何在Vue组件中添加grecaptcha onload方法。未加载时grecaptcha.render不是函数

const script = document.createElement("script");
 script.src = `${URL}?render=explicit&hl=TR`;
 script.async = true;
 script.defer = true;
 document.body.appendChild(script);
 this.initReCaptcha();


initReCaptcha: function () {
    setTimeout(function () {
       if (typeof grecaptcha === 'undefined') {
           this.initReCaptcha();
       } else {
          grecaptcha.render('recaptcha', {
          sitekey: 'XXXX',
          callback: this.submit,
          'expired-callback': this.expired
                        });
                    }
                }.bind(this), 100);
            }
Run Code Online (Sandbox Code Playgroud)

我将超时设置为1000时正在工作,但为时已晚。

javascript recaptcha vue.js

2
推荐指数
1
解决办法
2311
查看次数

标签 统计

javascript ×1

recaptcha ×1

vue.js ×1