问题描述
在 html里面,使用 state没有定义的属性,但是使用componentWillMount()方法将这个属性定义了,结果会出错,浏览器提示该属性未定义,无法引用
Cannot read property '0' of undefined
问题出现的环境背景及自己尝试过哪些方法
只有先定义一下,才可以
相关代码
// 请把代码文本粘贴到下方(请勿用图片代替代码)
this.state = {
// menu:[{name:''}]
}
你期待的结果是什么?实际看到的错误信息又是什么?
无语,不是说 render在componentWillMount后面吗
state,props -> componentWillMount -> render -> componentDidMount 这是挂载阶段
虚拟DOM是在render中进行的
具体还不太明白 题主要问什么问题
评论解答
希望能够帮助到你!