【发布时间】:2019-12-15 04:49:55
【问题描述】:
我无法理解如何从理智中获取数据。我已经阅读了文档,但我仍然感到困惑。
我尝试将数据记录到控制台,但它给了我一个错误,例如“请求的资源上不存在'Access-Control-Allow-Origin'标头。”
import React from "react";
import sanityClient from "@sanity/client";
const Post = () => {
const client = sanityClient({
projectId: "6sf5fafo",
dataset: "production",
useCdn: true
});
// fetching the data
client
.fetch('*[__type == "post"][0]{title, "name": author->name}', {})
.then(res => {
console.log("Post info: ", res); // Here is when i tried to log the data but gets an error message.
})
.catch(err => {
console.log(err);
});
return (
<div>
<h1>Hello</h1>
</div>
);
};
export default Post;
有人可以对我的代码进行一些编辑以正确地从理智中获取数据吗?非常感谢。
【问题讨论】:
-
一个快速的谷歌搜索就可以了:sanity.io/docs/front-ends/cors