Reactjs 无法从Gatsby JS上的GraphQL查询超链接
我正在写一个关于盖茨比JS的博客,我遇到了一个关于超链接的问题,我无法解决它 我有以下疑问Reactjs 无法从Gatsby JS上的GraphQL查询超链接,reactjs,graphql,gatsby,Reactjs,Graphql,Gatsby,我正在写一个关于盖茨比JS的博客,我遇到了一个关于超链接的问题,我无法解决它 我有以下疑问 const options = { renderNode: { "embedded-asset-block": (node) => { const alt = node.data.target.fields.title['es'] const url = node.data.t
const options = {
renderNode: {
"embedded-asset-block": (node) => {
const alt = node.data.target.fields.title['es']
const url = node.data.target.fields.file['es'].url
return <img alt={alt} src={url} />
},
[INLINES.HYPERLINK]: (node) => {
if(node.data.uri.indexOf('youtube.com') !== -1){
return(
<iframe width="560" height="315" src={node.data.uri} frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
)
}else{
return(
<a href={node.data.uri}>{node.content.value}</a>
)
}
}
}
}
我需要查询值(FelixDigital)
有人能帮我吗
非常感谢,您能在这段代码中执行调试器吗
很难说。。但是我要检查的是
节点的值。在我看来,内容似乎是一个数组,在数组的第一项中,你有值,因此在我看来,它应该更像是节点。内容[0]。值我猜你是在使用Contentful,使用GraphQL将数据拉入你的博客。对于Contentful,必须在JSON节点(所有富文本项)上使用documentToReactComponents。要获得FelixDigital,您可能需要执行以下操作:
import { documentToReactComponents } from '@contentful/rich-text-react-renderer';
return(
<div>
{documentToReactComponents(videos.videoItem.videoLinks.json, options)}
</div>
)
从'@contentful/rich text react renderer'导入{documentToReactComponents};
返回(
{documentoreactcomponents(videos.videoItem.videoLinks.json,选项)}
)
然后,这将使用您在const options
中设置的iframe并获取src uri
有关更多信息,请访问
import { documentToReactComponents } from '@contentful/rich-text-react-renderer';
return(
<div>
{documentToReactComponents(videos.videoItem.videoLinks.json, options)}
</div>
)