如何解决如何查询2张不同的图片?
我想查询2张图片,images/me.jpg
和images/boxing.png
。
不确定在graphql中怎么做:
query AboutQuery {
file(relativePath: { eq: ("images/me.jpg"|"images.boxing.png") }) {
childImageSharp {
fluid {
...GatsbyImageSharpFluid
}
}
}
}
解决方法
这应该有效:
query AboutQuery {
file(relativePath: { regex: "images" }) {
childImageSharp {
fluid {
...GatsbyImageSharpFluid
}
}
}
}
在GraphQL Query Reference中可以看到,可以使用正则表达式来匹配relativePath
,如果需要,您可以匹配"images"
。
您也可以选择使用in
过滤器(接受数组中的多个值)来匹配["images"]
:
query AboutQuery {
file(relativePath: { in: ["images"] }) {
childImageSharp {
fluid {
...GatsbyImageSharpFluid
}
}
}
}
作为单个值,正则表达式是最好的方法。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。