【发布时间】:2020-09-23 00:17:35
【问题描述】:
我是 React JS 的新手。我正在尝试开发一个简单的网页来呈现来自云 Firestore 的数据。我正在使用react-redux-firebase 来获取数据。它工作正常。现在我希望从云函数中获取数据。我已经成功部署了云功能。我什至可以使用axios 从云函数中获取数据。但我想使用react-redux-firebase。我搜索了很多,找不到一个例子。请帮帮我。
const firebase = getFirebase();
var animals = firebase
.functions()
.httpsCallable("getAllAnimals");
animals()
.then(result => {
console.log("result ------------- ", result)
})
.catch(error => console.log('errorrrrrrrr ' + error)
);
使用这个,我得到以下错误。
errorrrrrrrr Error: Response is missing data field.
【问题讨论】:
-
请编辑问题以显示您打算调用的可调用函数。请注意,您的客户端客户端专门尝试调用callable function,它应该在后端这样定义。
-
我不认为
react-redux-firebase是为了取代像 Axios 或 Fetch API 这样的请求库,最终你的 Cloud Function 是一个 HTTP 端点。您是否检查过它是否可以使用 Axios?您还可以共享函数代码和在反应组件中发出请求的 sn-p tha 吗? (现在功能代码好像不完整) -
@Happy-Monad,谢谢。使用 Axios 我可以获取数据。但我想在某一时刻集中我的数据。那就是我想使用 react-redux-firebase。
标签: reactjs firebase redux google-cloud-functions react-redux-firebase