【问题标题】:Gatsby.js (React) - graphql query in gatsby-browser.jsGatsby.js (React) - gatsby-browser.js 中的 graphql 查询
【发布时间】:2021-05-28 07:13:21
【问题描述】:

我在 Gatsby.js (React) 中有一个插件 TypeWriting。它看起来像这样:

/* file: gatsby-browser.js */
const typeWriting = () => {
  new Typewriter('#intro-typing', {
    strings: ['Drupal', 'WordPress', 'OpenCart'],
  });
}
export const onInitialClientRender = () => {
  typeWriting();
}

我想为“字符串”设置 - 来自 graphql 查询的自己的数组

如何在 gatsby-browser.js 中使用 graphql 查询?

【问题讨论】:

    标签: reactjs gatsby


    【解决方案1】:

    gatsby-browser.js 是一个文件,可让您响应浏览器中的操作,并将您的网站包装在其他组件中。 Gatsby 浏览器 API 为您提供了许多与 client-side of Gatsby 交互的选项。所以我认为你不能在任何 API 或方法之外触发任何类型的 GraphQL 查询。

    如果您希望 strings 数组“自动化”,您可以使用 environment variables 并将其作为数组的值放置。

    【讨论】:

      猜你喜欢
      • 2020-03-23
      • 2019-02-20
      • 1970-01-01
      • 2020-06-20
      • 2020-10-22
      • 2019-06-18
      • 2019-11-22
      • 2019-04-02
      • 1970-01-01
      相关资源
      最近更新 更多