我跟著Gatsby Docs 關于 Gatsby中的數據,他們向我展示了如何在其中的 siteMetadata 塊中創建 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 } } }`我想將我的網絡應用程序中的所有數據與其余代碼分開,并且全部包含在一個地方,例如我可能有一個看起來像的文件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'或者將我的文本和鏈接分開到單獨的文件中可能是更好的做法?我只是覺得將所有數據變量插入到 siteMetadata 可能不是最好的方法,但也許我錯了?
使用 Gatsby 時在何處記錄數據以及如何將數據導入 gatsby.config.js
LEATH
2022-07-08 18:33:29