我还是 React 的新手。我只是想让我的投资组合用好的技术构建。我对 gatsbyjs 很感兴趣。现在,我得到了一个错误。它说
未知论点'frontmatter'
我对此一无所知。这与 graphql 或 gatsbyjs 有关吗?
有人可以帮我解决这个问题吗?
我正在从“LevelUp 教程” channel 观看 youtube 教程。
https://www.youtube.com/watch?v=VxVKMJThh04&list=PLLnpHn493BHHfoINKLELxDch3uJlSapxg&index=5
import React from 'react'
import Helmet from 'react-helmet'
import { graphql } from "gatsby"
export default function Template({ data }) {
const { markdownRemark: post } = data; //sama dengan const post=data.markdownRemark
// const { markdownRemark } = data // data.markdownRemark holds our post data
return (
<div>
<h1>{post.frontmatter.title}</h1>
<div dangerouslySetInnerHTML={{ __html: post.html }} />
</div>
)
}
export const postQuery = graphql`
query BlogPostByPath($path : String!){
markdownRemark(frontmatter:{path: { eq:$path}}){
html
frontmatter{
path
title
}
}
}
最佳答案
转到您的 gatsby-config.js。
{
resolve: `gatsby-source-filesystem`,
options: {
name: `pages`,
path: `${__dirname}/src/pages`,
},
},
确保您的页面文件夹或子文件夹中有(有)*.md 文件。
这解决了我的问题,未知参数“frontmatter”。如果它不适合您,请查看教程。 Creating a Blog with Gatsby
关于javascript - 为什么我的 gatsby 应用程序显示 Unknown argument 'frontmatter' 错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58015949/