Javascript 为什么在这个POST请求中then()处理程序函数的参数用大括号括起来?
所以,这里是整个请求:Javascript 为什么在这个POST请求中then()处理程序函数的参数用大括号括起来?,javascript,Javascript,所以,这里是整个请求: fetch(`/api/quotes?quote=${quote}&person=${person}`{ 方法:“POST”, }) .then(response=>response.json()) 。然后({quote})=>{ const newQuote=document.createElement('div'); newQuote.innerHTML=` 恭喜你,你的报价被添加了! ${quote.quote} -${quote.person} 转到以请求并查看
fetch(`/api/quotes?quote=${quote}&person=${person}`{
方法:“POST”,
})
.then(response=>response.json())
。然后({quote})=>{
const newQuote=document.createElement('div');
newQuote.innerHTML=`
恭喜你,你的报价被添加了!
${quote.quote}
-${quote.person}
转到以请求并查看所有报价
`
newQuoteContainer.appendChild(newQuote);
});代码>您的响应是一个带有atribute的对象引号
{quote}
将获取该对象并将属性的内容分配给quote
请参见此示例:
让foo={
酒吧:5间
}
函数printbar({bar}){
console.log(bar)
}
printbar(foo)
您的响应是一个带有atribute引号的对象{quote}
将获取该对象并将属性的内容分配给quote
请参见此示例:
让foo={
酒吧:5间
}
函数printbar({bar}){
console.log(bar)
}
printbar(foo)
Hey Marcin,在then()的第二步中,您已经将响应体解析为Json。因此,接下来要做的就是将其作为then(result)=>{console.log(result.quote.id);}
。我没有见过类似({quote})的东西。检查它并让我知道Hey Marcin,在then()的第二步中,您已经将响应体解析为Json。因此,接下来要做的就是将其作为then(result)=>{console.log(result.quote.id);}
。我没有见过类似({quote})的东西。检查一下,让我知道