我一直在努力解决这个问题:
我的前面的事情看起来像:
---
path: '/path-to/'
title: 'Title of Post'
indexImage: './img.jpg'
---
Run Code Online (Sandbox Code Playgroud)
将我的图像放在与我的index.md文件相同的文件夹中.
在我的templates/post.js文件中,我有以下行:
<img src={ post.frontmatter.indexImage }></img>
Run Code Online (Sandbox Code Playgroud)
认为这将拉入前面列出的来源.我的post.js查询是:
export const postQuery = graphql`
query BlogPostByPath($path: String!) {
markdownRemark(frontmatter: { path: { eq: $path } }) {
html
frontmatter {
path
title
indexImage
}
}
}
`;
Run Code Online (Sandbox Code Playgroud)
以下是错误消息:
GraphQL Error Field "indexImage" of type "File" must have a selection of subfields. Did you mean "indexImage { ... }"?
Run Code Online (Sandbox Code Playgroud)
为什么这不起作用的任何想法?我还是盖茨比的新手,所以这可能是一个让我头疼的问题.提前致谢.