class 是ES6的写法。getIntialState是ES5的hook函数,不能在这里用。
定义初始state应该在constructor中:constructor(props){
super(props); this.state={ ss:"xxx" }
}
感觉this.handlechange这里写的有问题,constructor里需要绑定一下这个方法,否则this丢了应该找不到这个方法?
this.handlechange
constructor(props) { super(props) this.handleChange = this.handleChange.bind(this) }
如果不想用constructor,直接定义state 在class从 直接写`class ... {
state = {
sss
// this.state 可以获取}`
class 是ES6的写法。
getIntialState是ES5的hook函数,不能在这里用。
定义初始state应该在constructor中:
constructor(props){
}
感觉
this.handlechange
这里写的有问题,constructor里需要绑定一下这个方法,否则this丢了应该找不到这个方法?如果不想用constructor,直接定义state 在class从 直接写
`
class ... {
state = {
}
// this.state 可以获取
}
`