下面的代码将存储一个自动生成名称的对象。相反,我希望能够提前指定该名称。我该怎么做呢?谢谢
const request = new Request('firebaseUsr.json',{
method:'POST',
headers:{
name:formState.inputValues.username,
},
body:JSON.stringify({
username,
password
})
})
fetch(request)
.then(response => {
if (response.status === 200) {
return response.json();
} else {
throw new Error('Something went wrong on api server!');
}
})
.then(response => {
console.debug(response);
// ...
}).catch(error => {
console.error(error);
});发布于 2020-06-15 11:50:42
根据Firebase Realtime Database REST API的文档,POST等同于使用随机ID的推送操作,因此,如果您不想使用POST,请不要使用POST。相反,您可能需要一个PUT,它允许您指定要写入的节点的完整路径。您在请求的路径中确定该路径。因此,您应该指定"/path/ to /node.json“,以便只更新"/path/to/node”。
https://stackoverflow.com/questions/62380998
复制相似问题