Javascript 从控制台中的GraphQLAPI调用打印值
我一直在努力解决这个问题,非常感谢你的帮助。我希望能够使用console.log在控制台中打印标题值Javascript 从控制台中的GraphQLAPI调用打印值,javascript,graphql,Javascript,Graphql,我一直在努力解决这个问题,非常感谢你的帮助。我希望能够使用console.log在控制台中打印标题值 `<script> const url = "***"; const opts = { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ query: "
`<script>
const url = "***";
const opts = {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ query: "*[_type == 'post']{ _updatedAt, _createdAt, title}[0]" })
};
fetch(url, opts)
.then(res => res.json())
.then(console.log)
.catch(console.error);
</script>`
您希望访问结果对象的标题字段。试试这个:
fetch(url, opts)
.then(res => res.json())
.then(console.log)
.catch(console.error);
如果result是一个对象,我猜您需要在日志中指定
result
fetch(url,opts)
.then(res=>res.json())
.then(data=>console.log(data.result))
.catch(控制台错误);
fetch(url, opts)
.then(res => res.json())
.then(console.log)
.catch(console.error);