GraphQL自定义日期和格式字符串

问题描述 投票:1回答:1

我有这个:

export const pageQuery = graphql`
  query {
    site {
      siteMetadata {
        title
      }
    }
    allMdx(sort: { fields: [frontmatter___date], order: DESC }) {
      edges {
        node {
          excerpt
          fields {
            slug
          }
          frontmatter {
            date(formatString: "DD 'de'  MMMM, YYYY", locale: "pt")
            title
            description
          }
        }
      }
    }
  }
`

在行中->> date(formatString: "DD 'de' MMMM, YYYY", locale: "pt") 我必须插入字符串,但是此“ de”无效。我知道我想像这样显示日期: 25 de March, 2020. 但是结果是: 25 '32' March, 2020. 我知道这行不通,我知道为什么,但是我做对了。我在带有graphql的Gatsbyjs中使用

javascript graphql gatsby date-formatting template-literals
1个回答
0
投票

要在格式字符串中转义字符,可以将字符包装在方括号中。

© www.soinside.com 2019 - 2024. All rights reserved.