我跟著Gatsby Docs 關(guān)于 Gatsby中的數(shù)據(jù),他們向我展示了如何在其中的 siteMetadata 塊中創(chuàng)建 graphql 變量gatsby.config.jsmodule.exports = { siteMetadata: { title: `Title from siteMetadata`, }, plugins: [ `gatsby-plugin-emotion`, { resolve: `gatsby-plugin-typography`, options: { pathToConfigModule: `src/utils/typography`, }, }, ],}然后可以使用 graphql 查詢訪問它import React from "react"import { graphql } from "gatsby"import Layout from "../components/layout"export default ({ data }) => ( <Layout> <h1>About {data.site.siteMetadata.title}</h1> <p> We're the only site running on your computer dedicated to showing the best photos and videos of pandas eating lots of food. </p> </Layout>)export const query = graphql` query { site { siteMetadata { title } } }`我想將我的網(wǎng)絡(luò)應(yīng)用程序中的所有數(shù)據(jù)與其余代碼分開,并且全部包含在一個(gè)地方,例如我可能有一個(gè)看起來像的文件navLinks = ["Home", "About", "Contact"]homePageIntro = "Hello! Thank you for visiting my website"logo = 'https://aws.amazon.com/mys3.logo'contactPhoto = 'https://aws.amazon.com/mys3.logo'aboutPageFirstPar = 'This is the first paragraph on the about page'aboutPageSecondPar = 'This is the Second paragraph on the about page'或者將我的文本和鏈接分開到單獨(dú)的文件中可能是更好的做法?我只是覺得將所有數(shù)據(jù)變量插入到 siteMetadata 可能不是最好的方法,但也許我錯(cuò)了?
使用 Gatsby 時(shí)在何處記錄數(shù)據(jù)以及如何將數(shù)據(jù)導(dǎo)入 gatsby.config.js
LEATH
2022-07-08 18:33:29