尝试以这种方式加载SVG图像时:
export const query = graphql`
query {
fileName: file(relativePath: { eq: "logo_large.svg" }) {
childImageSharp {
fluid(maxWidth: 1060) {
...GatsbyImageSharpFluid_withWebp_tracedSVG
}
}
}
}
`
Run Code Online (Sandbox Code Playgroud)
我懂了 TypeError: Cannot read property 'childImageSharp' of null
如果我尝试完全相同但使用.jpg或.png图像,则它可以工作,因此相对路径必须正确。我应该特别考虑SVG吗?