javascript - 如何从 react-native 中的函数返回数据
问题描述
我正在尝试从函数返回数据,但没有得到正确的数据
export const getApi = (url) => {
return fetch(url)
.then((response) => response.json())
.then((json) => {
console.log(json);
})
}
{"_U": 0, "_V": 0, "_W": null, "_X": null}
这是我的回应
我在这里叫它
componentDidMount(){
const data= getApi(banner)
console.log('data',data)
}
解决方案
不确定您要在宏伟计划中完成什么,但根据代码片段,您需要这样做:
export const getApi = (url) => {
return fetch(url)
.then((response) => response.json())
.then(json => json)
}
然后像这样使用它:
componentDidMount(){
getApi(banner).then(data => console.log("data", data))
}
推荐阅读
- dart - Dart:从列表中访问函数
- javascript - 在 Zapier 中编辑单词
- python - nn.LSTM() 收到无效的参数组合
- hover - 添加了隐藏元素,但现在我的悬停效果不再起作用
- c - C:在make文件中使用-D编译
- ubuntu - 为什么virtualbox无法在Ubuntu20.04上安装
- azure - Servicebus 和 Function App(Vnet) 集成
- java - 使用 WebClient 为 multipart/form-data 发送 POST 请求的 Content-Length 标头
- android - (Kotlin)我想在不使用 addValueEventListener 的情况下从实时数据库(firebase)中检索数据
- python - 如何用python计算音频频谱中的频率峰值