首页 > 解决方案 > React recaptcha google 根本没有显示

问题描述

react-recaptcha-google我已按照此处的示例安装并添加到我的应用程序中: https ://medium.com/codeep-io/how-to-use-google-recaptcha-with-react-38a5cd535e0d

但是什么都没有出现,没有错误,什么也没有。

import React, { Component } from 'react';

import ReactDOM from 'react-dom';

import { ReCaptcha } from 'react-recaptcha-google';

class MyComponent extends Component {
    constructor(props, context) {
        super(props, context);

    componentDidMount() {
        this.getProducts();

        if (this.captchaDemo) { // <- this is getting skipped
            console.log("started, just a second...")
            this.captchaDemo.reset();
            //this.captchaDemo.execute();
        }
    }

    onLoadRecaptcha() {
        if (this.captchaDemo) {
            this.captchaDemo.reset();
            //this.captchaDemo.execute();
        }
    }

    verifyCallback(recaptchaToken) {
        // Here you will get the final recaptchaToken!!!  
        console.log(recaptchaToken, "<= your recaptcha token")

    render() {
        return (
            <div className="row">
                                    <ReCaptcha
                                        ref={(el) => { this.captchaDemo = el; }}
                                        size="normal"
                                        render="explicit"
                                        sitekey="our correct key"
                                        onloadCallback={this.onLoadRecaptcha}
                                        verifyCallback={this.verifyCallback}
                                    />

            </div>
        );
    }
}

ReactDOM.render(<MyComponent />, document.getElementById('myComponent'));

componentDidMount()也正在跳过中的条件。

我已经不知道该怎么做才能让它发挥作用。有什么建议么?

我也试过:

我们的密钥 100% 正确,因为我们将它用于同一站点上的其他验证码(用 Razor 编写)。

标签: reactjsrecaptchareact-google-recaptcha

解决方案


我刚刚想通了-我失踪了

<script src="https://www.google.com/recaptcha/api.js" async defer></script>

在页面上,添加并显示验证码。


推荐阅读