Next.js从Prismic获取数据遭CORS拦截,请求技术协助
Prismic数据请求遭CORS拦截,无法获取博客内容
我在搭建简易博客时,尝试通过Prismic客户端获取指定UID的博客内容,但浏览器控制台提示CORS错误,无法正常加载数据。
我的代码:
import { createClient } from '../../../prismicio' import React, { useEffect, useState } from 'react' export default function Page() { const [page, setPage] = useState(null) useEffect(() => { const fetchData = async () => { const client = createClient() const uid = 'my-first-post' // Replace with your desired UID try { const response = await client.getByUID('blog_content', uid) setPage(response) console.log(response) } catch (error) { console.error('Error fetching data:', error) } } fetchData() }, []) return ( <div className="mt-40"> {page ? <h1>Page is fetched.</h1> : <p>Loading...</p>} </div> ) }
控制台报错信息:
from origin 'http://localhost:3000' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
我检查过代码逻辑,没发现明显问题,希望有人能帮忙排查解决,有疑问我会及时回复。
内容的提问来源于stack exchange,提问作者Iroro
相关产品推荐
相关产品推荐

