不得不说React-Native的Component生命周期还真是坑,文档里说在执行到componentDidMount方法后就可以开开心心的搞事了,没想到在这里加载完网络数据执行state更新的时候居然会影响到Navigator中新页面的启动。具体的问题是这样的:
componentDidMount() {
this._fetchData();
}
在componentDidMount方法中执行了fetchData方法来拉取网络数据,并在拉取到数据后通过更新state来更新UI
_fetchData() {
let url = 'http://www.exsample.com/comment';
fetch(url)
.then((response) => response.json())
.then((responseData) => {