export default class SignUp extends Component {
constructor(props) {
super(props);
this.state = {
value: ''
}
}
transferValue(val) {
setState({
value: val
})
}
render() {
return (
<Form>
<Input dataValue={this.state.value} transferValue={val => this.transferValue(val)} id="formCaptcha" type="text" />
<Input dataValue={this.state.value} transferValue={val => this.transferValue(val)} id="formCaptcha" type="text" />
<Input dataValue={this.state.value} transferValue={val => this.transferValue(val)} id="formCaptcha" type="text" />
</Form>
)
}
}
export class Input extends Component {
handleChange(event) {
this.setState({
value: event.target.value
});
this.props.transferValue(event.target.value)
}
render() {
const {
id,
type,
style,
...other
} = this.props;
return (
<div>
<input ref={id} type={type} value={this.state.value} onChange={() => this.handleChange(event)} />
</div>
)
}
}
export class Form extends Component {
render() {
for (let item of this.props.children) {
//在这获取Inpuo的value
console.log(item)
}
return (
<form>
{this.props.children}
</form>
)
}
}
其实你代码结构写的有问题,既然你需要
form
获取数据,为啥不直接用SignUp
来控制数据?