为什么'emailjs'没有定义为no-undef?

问题描述 投票:0回答:2

我正在关注此处找到的 Emailjs 教程 - https://www.emailjs.com/docs/tutorial/creating-contact-form/

当网页编译失败时,我收到这些错误行:

Failed to compile./src/components/SwatForm.js

Line 42:29:  'emailjs' is not defined  no-undef
  
Line 52:33:  'emailjs' is not defined  no-undef
  
Line 64:33:  'emailjs' is not defined  no-undef

Search for the keywords to learn more about each error.
This error occurred during the build time and cannot be dismissed.

这是我的 React 应用程序中教程的实际代码。

import React, { Component } from 'react';
import { Container, Row, Col, Button, NavLink } from 'reactstrap';
import { Link } from 'react-router-dom';
import 'bootstrap/dist/css/bootstrap.min.css';
import groupPicture from "../church2019.jpg";
import Image from 'react-bootstrap/Image';
import './Site.css';



export class SwatForm extends Component {
    static displayName = SwatForm.name;
    constructor(props) {
        super(props);
        this.state = {
            name: "",
            email: "",
            feedback: "",
        };
    }
    handleInputChange(event) {
        event.preventDefault();
        const target = event.target;
        const name = target.name;
        const value = target.value;
        this.setState({ [name]: value });
    }

    render() {

        return (

            <Container>
                <html>

                <head>
                    <title>Contact Form</title>
                    <script type="text/javascript" src="https://cdn.jsdelivr.net/npm/emailjs-com@2/dist/email.min.js"></script>
                    <script type="text/javascript">
                        (function() {
                            // https://dashboard.emailjs.com/admin/integration
                            emailjs.init('user_0rJrw0xxhrNqhld3WUc3q')
                        })();
    </script>
                    <script type="text/javascript">
                        window.onload = function() {
                            document.getElementById('contact-form').addEventListener('submit', function (event) {
                                event.preventDefault();
                                // generate a five digit number for the contact_number variable
                                this.contact_number.value = Math.random() * 100000 | 0;
                                // these IDs from the previous steps
                                emailjs.sendForm('contact_service', 'contact_form', this)
                                    .then(function () {
                                        console.log('SUCCESS!');
                                    }, function (error) {
                                        console.log('FAILED...', error);
                                    });
                            })
                        }
                        </script>
                        <script type="text/javascript" src="https://cdn.jsdelivr.net/npm/emailjs-com@2/dist/email.min.js"></script>
                        <script type="text/javascript">
                            (function() {
                                emailjs.init("user_0rJrw0xxhrNqhld3WUc3q")
})();
</script>
                </head>



                <form id="contact-form">
                    <input type="hidden" name="contact_number" />
                    <label>Name</label>
                    <input type="text" name="user_name" />
                    <label>Email</label>
                    <input type="email" name="user_email" />
                    <label>Message</label>
                    <textarea name="message"></textarea>
                    <input type="submit" value="Send" />
                </form>
                    </html>
            </Container>

        );
    }
}

reactjs forms html-email
2个回答
1
投票

有一个使用该库的包。我认为你应该使用它。

https://www.npmjs.com/package/emailjs-com

https://www.emailjs.com/docs/examples/reactjs/


0
投票

我可以看到你正在使用 React。

请遵循此处的文档:https://www.emailjs.com/docs/examples/reactjs/

安装此软件包:npm i @emailjs/browser

它会起作用..

© www.soinside.com 2019 - 2024. All rights reserved.