import React, { PureComponent } from 'react'
export default class App extends PureComponent {
constructor(){
super();
// 给默认选中orange
this.state={
currentfruit:"orange"
}
}
render() {
return (
<div>
<form onSubmit={e=>this.handleSubmit(e)}>
{/* 在react的select中,可以增加一个value值,设置其默认值;
在以前的普通的js里面,是通过给option添加selected表示默认值 */}
<select name="fruits"
onChange={e=>this.optionChange(e)}
value={this.state.currentfruit}>
<option value="apple">苹果</option>
<option value="banana">香蕉</option>
<option value="orange">橘子</option>
<option value="watermelon">西瓜</option>
</select>
<input type="submit" value="提交"/>
</form>
</div>
)
}
optionChange(event){
this.setState({
currentfruit:event.target.value
})
}
}