我在我的项目中设置了axios,如下所示
在我的src/
文件夹中创建了一个axios.js文件,如下所示:
import axios from 'axios';
const instance = axios.create({
baseURL : 'https://myprojectname-11651.firebaseio.com/'
});
export default instance;
然后在我使用axios的主组件中,我像这样使用它:
import axios from '../axios.js';
// removing code thats not necessary for this example
componentDidMount() {
// alert();
axios.get('/habits/badHabits.json')
.then( (resp) => {
console.log(resp);
})
}
我在控制台中收到401错误,firebase的仪表板似乎与一年前相比发生了变化,我并不是不能像一年前那样在firebase中使用axios。
我的数据库是这样的:
如何在firebase中使用axios?我必须从npm安装firebase吗?
发布于 2018-08-27 03:15:13
我感觉你把实时数据库REST API和Firestore混淆了。
根据您问题中的图片,您正在使用Firestore。
对于Firestore,“所有REST API端点都存在于基本URL https://firestore.googleapis.com/v1beta1/下”,请参阅文档here。
另一方面,正如详细描述的那样,Real Time DB REST API端点有一个基本here,如https://docs-examples.firebaseio.com/rest/……这与您问题中的URL相似。
https://stackoverflow.com/questions/52029060
复制相似问题