错误:输入是一个空元素标签,不能有`children`也不能使用`dangerouslySetInnerHTML`。

6
import React , { Component } from 'react'

class Login extends Component{
    constructor(props){
        super(props)

    }
    render(){
        return(
            <form className="login-form">
                <h1>login</h1>
                <div>
                    <div className="form-group">
                        <label for="name">
                            Name :
                        </label>
                        <input name="name" type="text" value="" placeholder="Your Name" />
                    </div>
                    <div className="form-group">
                        <label for="password">
                            Password :
                        </label>
                        <input name="password" type="Password" value="" placeholder="Password" />
                    </div>
                    <input type="submit">Submit</input>
                </div>
            </form>
        )
    }
}

export default Login
2个回答

11

我认为问题出在这里,

//input is an empty tag and you have provided Submit as children here
<input type="submit">Submit</input>  

它应该只是这样简单的,

<input type="submit" value="Submit" />

3
ravibagul91的回答是正确的。 input 是一个自闭合元素,你不能在其中添加子元素。
或者,你可以使用按钮:
<button type="submit">Submit</button>

转换为:

<input type="submit" value="Submit" />

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接