请问,如何将fetch的输出保存到变量中 - 能够像对象一样使用它?
这是代码:
var obj;
fetch("url", {
method: "POST",
body: JSON.stringify({
"filterParameters": {
"id": 12345678
}
}),
headers: {"content-type": "application/json"},
//credentials: 'include'
})
.then(res => res.json())
.then(console.log)
Run Code Online (Sandbox Code Playgroud)
决赛console.log将展示一个对象.但是当我试图将它保存到变量.then(res => obj = res.json())而console.log(obj)不是保存Object时,却是Promise.
请问,如何把它变成保存在变量中的对象?