【发布时间】:2019-01-28 02:27:41
【问题描述】:
我是 React 的新手,所以请原谅这个问题中的任何错误!
我目前正在尝试使用基本的登录表单:
import React, { Component } from 'react';
import { Input, Form, Button } from 'semantic-ui-react'
class LoginForm extends Component {
state = { username: '', password: '' }
handleChange = (e, { name, value }) => this.setState({ [name]: value })
handleSignIn(e) {
e.preventDefault()
this.props.onSignIn(this.username, this.password)
}
render() {
const { username, password } = this.state
return (
<div className="login-container">
<Form onSubmit={this.handleSignIn.bind(this)}>
<Form.Field>
<Input icon="user" iconPosition="left" placeholder="Username" type="text" ref="username" onChange={this.handleChange}/>
</Form.Field>
<Form.Field>
<Input icon="user secret" iconPosition="left" placeholder="Password" type="password" ref="password" onChange={this.handleChange}/>
</Form.Field>
<Form.Field>
<Button type="submit" className="inputSpacing" color="yellow"><Icon name='lock' />Login</Button>
</Form.Field>
</Form>
</div>
);
}
}
export default LoginForm;
我面临的问题是state = { username: '', password: '' } 行生成以下错误:
ERROR in ./react-client/src/components/coreComponents/loginForm.js
Module build failed: SyntaxError: D:/path/to/project/react-client/src/components/coreComponents/loginForm.js: Unexpected token (6:8)
我从here 复制了这个,但即使是那里的代码 sn-ps 也会给我这个错误。我错过了什么? :(
【问题讨论】:
-
你能和我们分享你的 .babelrc 文件吗?
-
是的,我跳过了错误并在我的回答中快速得出结论。问题可能是类字段提案。
-
看看this issue,好像是同样的问题
-
是的,绝对是@Philippe。
标签: reactjs semantic-ui