我正在尝试使用 react js 制作评论应用程序。我希望我的评论发布在我的 firebase 数据库上,我正在使用 axios 来帮助我做到这一点,但是当我提交评论时,我收到了这两个错误
1.xhr.js:177 POST https://expresate-react-default-rtdb.firebaseio.com/Comments.json 400 (Bad Request)
2. Error: Request failed with status code 400
at createError (createError.js:16)
at settle (settle.js:17)
at XMLHttpRequest.handleLoad (xhr.js:62)
我尝试了所有方法,但我不知道为什么它不起作用。
这是代码
import axios from '../../axios-comments';
inputHandler = (event) => {
this.setState({input: event.target.value});
}
onSubmitComment = () => {
let {comments,input} = this.state;
comments.splice(0,input);
this.setState({comments: comments});
const cmnt = this.state.input;
axios.post('/Comments.json',cmnt)
.then(Response => {
console.log(Response);
})
.catch(error => console.log(error));
}
我将 firebase 链接保存在另一个文件中,然后将其导入到我需要的文件中。
import axios from "axios";
const instance = axios.create({
baseURL: 'https://expresate-react-default-rtdb.firebaseio.com/'
});
export default instance;
谁能帮我解决这个问题? 谢谢!