javascript - TypeError:无法读取 null 的属性“流体”
问题描述
我正在尝试从内容数据中获取图像到 gatsby 站点。我可以检索文本内容。
我浏览了gatsby-image
插件文档。看起来不错。
const getBlogList = graphql`
{
blogs: allContentfulBlog {
edges {
node {
id
title
image {
fluid(maxWidth:250) {
...GatsbyContentfulFluid_tracedSVG
}
}
}
}
}
}
`;
<StaticQuery
query={getBlogList}
render={ data => {
return({data.blogs.edges.map(({node})=>{
return(<div><Img fluid={node.image.fluid} /></div>)
})
}
)
}} />
我找不到哪里出错了。我有一个错误
TypeError:无法读取 null 的属性“流体”。
解决方案
当您获得 null 错误的读取属性时,这意味着父属性为 null。也许某个节点没有任何图像属性,所以当您尝试读取 null 的流体时,您会遇到错误。在使用它来达到流体属性之前,尝试检查地图函数上节点中是否存在图像。
推荐阅读
- getstream-io - 一篇文章 = 一项活动
- sql - SQL 查找分析函数中每个值的最小值
- apache-camel - 如何使用 Camel 连接来自不同数据源的两个相同表?
- angular - 角 6 | 服务器端渲染:问题“未定义窗口”
- webpack - 为什么 tns 运行 android 工作,但是当我添加 --bundle 它没有
- tableau-api - 即使某个类别不可见,tableau 也会显示计算中的类别
- docusignapi - apiClient.ConfigureJwtAuthorizationFlow,在 localhost 中返回 OAuthToken,但在测试环境中返回 null
- javascript - 如果 DIV 有带有特定文本的 P,则隐藏 DIV
- python - 为方法跳过“self”的装饰器
- javascript - pg-promise db 调用在“then”函数中返回未定义