43 lines
1.3 KiB
JavaScript
43 lines
1.3 KiB
JavaScript
/*
|
||
* @Author: chenxuan
|
||
* @Date: 2022-06-21 23:45:51
|
||
* @LastEditTime: 2022-06-26 20:04:33
|
||
* @LastEditors: chenxuan
|
||
*/
|
||
import React,{Component} from 'react'
|
||
export default class Count extends Component{
|
||
increement=()=>{
|
||
const {value}=this.selectNumber
|
||
this.props.jia(value*1)
|
||
}
|
||
decreement=()=>{
|
||
const {value}=this.selectNumber
|
||
this.props.jian(value*1)
|
||
}
|
||
increementOdd=()=>{
|
||
const {value}=this.selectNumber
|
||
if(this.props.state.count%2!==0){
|
||
this.props.jia(value*1)
|
||
}
|
||
}
|
||
increementSync=()=>{
|
||
const {value}=this.selectNumber
|
||
this.props.jiaAsync(value*1,1000)
|
||
}
|
||
render(){
|
||
return(
|
||
<div>
|
||
<h1>当前求和为:{this.props.state.count}</h1>
|
||
<select name="" id="" ref={c=>this.selectNumber=c}>
|
||
<option value="1">1</option>
|
||
<option value="2">2</option>
|
||
<option value="3">3</option>
|
||
</select>
|
||
<button onClick={this.increement}>+</button>
|
||
<button onClick={this.decreement}>-</button>
|
||
<button onClick={this.increementOdd}>计数再加</button>
|
||
<button onClick={this.increementSync}>异步再加</button>
|
||
</div>
|
||
)
|
||
}
|
||
} |