【发布时间】:2016-12-04 09:54:47
【问题描述】:
您好,我尝试像这样设置 fetch 调用的状态:
getCats() {
fetch(GLOBALS.API + '/specials.php?action=getCats&key=' + GLOBALS.KEY)
.then((response) => response.json())
.then((responseJson) => {
this.setState = ({
dataSource: "test"
});
Alert.alert("test");
})
.catch((error) => {
console.log(error.toString());
});
}
componentDidMount() {
this.getCats();
console.log(this.state.dataSource);
}
但行:
console.log(this.state.dataSource);
返回我未定义 我收到“测试”警报
什么问题?
很多
【问题讨论】:
-
检查我的答案
-
我很高兴它对你有用。你也可以投票吗:-)
标签: android react-native fetch