扫码关注官方订阅号
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 可以获取}`
微信扫码关注PHP中文网服务号
QQ扫码加入技术交流群
扫描下载App
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
PHP学习
技术支持
返回顶部
class 是ES6的写法。
getIntialState是ES5的hook函数,不能在这里用。
定义初始state应该在constructor中:
constructor(props){
}
感觉
this.handlechange
这里写的有问题,constructor里需要绑定一下这个方法,否则this丢了应该找不到这个方法?如果不想用constructor,直接定义state 在class从 直接写
`
class ... {
state = {
}
// this.state 可以获取
}
`