如何解决Graphql过滤掉特定图像以使其不显示?
我当前的图像组件会映射文件夹中的所有图像并显示它们,但是我想过滤掉我的两个图像,这样我就可以将它们应用于另一个页面,而不是与其他所有图像一起显示在当前页面上我的文件夹。
我有一张要过滤掉的图像background.jpg
和background-2.jpg
const data = useStaticQuery(graphql`
query {
allFile(filter: { extension: { regex: "/(jpg)|(png)|(jpeg)/" },// So this line filters out background.jpg,but I can't seem to
filter out both background.jpg and background-2.jpg?
base: {ne: "background.jpg"}
}) {
edges {
node {
base
childImageSharp {
fluid(maxHeight: 600,maxWidth: 600) {
...GatsbyImageSharpFluid
}
}
}
}
}
}
`)
解决方法
您可以使用mvn test -DthreadCount=5
(甚至另一个正则表达式)或name
规则过滤节点nin
。
ne
上面的查询应该可以解决问题。如果不是,则可以始终使用const data = useStaticQuery(graphql`
query {
allFile(filter: {
extension: { regex: "/(jpg)|(png)|(jpeg)/" } }
name: {ne: "background"})
{
edges {
node {
base
childImageSharp {
fluid(maxHeight: 600,maxWidth: 600) {
...GatsbyImageSharpFluid
}
}
}
}
}
}
`)
规则创建例外数组,或使用另一个正则表达式排除背景名称。
更多信息:https://www.gatsbyjs.com/docs/graphql-reference/#filter
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。