##
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 可以取得
}
`