gpt4 book ai didi

javascript - 哪个是第一个被调用的?构造函数或 componentDidMount 或 Render

转载 作者:行者123 更新时间:2023-12-03 13:17:44 24 4
gpt4 key购买 nike

正如我已经阅读了在线和官方文档。订单是
构造函数-> ComponentWillMount -> 渲染-> ComponentDidMount 等。

class Navigation extends Component {
constructor(props) {
super(props);
console.log('constructor', this);
this.state = { items: [ ] };
}

componentDidMount() {
console.log('componentDidMount');

if ( toDisplay( ) ) {
api.bringCats()
.then( categories => {
const tot_cat = categories.map( cat => { return {name: cat.name, link: cat.link}; })
this.setState({items: tot_cat,})
})
}
}

render() {
console.log("render")
//some stuff
}
}

im expecting the the log to be in this order 1. constructor 2. ComponentDidMount 3. render



即时日志 thisconstructor内部构造方法。我能够获得 items 的值(value)在 componentDidMount 中得到它的值(value)为什么会这样?及其以正确的顺序记录(构造函数->didmount->render)但是为什么我得到 items 的值甚至在调用 componentDidMount 之前.

我正在使用 <Navigation/>内部组件 <Header/>
Header extends Component{
render(){
return (<div> <Navigation/> </div>);
}
}

最佳答案

我正在尝试一些东西,发现这工作正常。
window.cnj = require('circular-json')/* 我在起点第一行添加了这个,所以我可以在所有导入中访问它。 */
window.props = JSON.parse(window.cnj.stringify(simple));
我可以访问window.props来自开发工具及其按预期工作。
sample可以是字符串、数组、普通对象或圆形对象。

关于javascript - 哪个是第一个被调用的?构造函数或 componentDidMount 或 Render,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44892906/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com