【发布时间】:2019-02-20 00:59:27
【问题描述】:
我收到此错误消息:TypeError: Cannot read property 'fixed' of null。
该项目包括 Javascript、Reactjs、Gatsbyjs 和 Contentful。
错误代码部分:
3 | import { styles } from '../../utils'
4 | import Img from 'gatsby-image'
5 |
> 6 | export default function Product({ product }) {
7 | const { name, price, ingredients } = product;
8 | const { fixed } = product.img;
9 |
现有代码:
import React from 'react'
import styled from 'styled-components'
import { styles } from '../../utils'
import Img from 'gatsby-image'
export default function Product({ product }) {
const { name, price, ingredients } = product;
const { fixed } = product.img;
return (
<ProductWrapper>
<Img fixed={fixed} className="img" />
<div className="text">
<div className="product-content">
<h3 className="name">{name}</h3>
<h3 className="price">${price}</h3>
</div>
<p className="info">{ingredients}</p>
</div>
</ProductWrapper>
)
}
Fixed 在 Menu.js 中定义
img {
fixed(width: 150, height: 150) { ...GatsbyContentfulFixed_tracedSVG
在花了很多时间寻找解决方案后,我决定寻求任何帮助。
谢谢
【问题讨论】:
-
Menu.js 长什么样子?
-
JavaScript 和 Java 是完全不同的语言。请不要使用 Java 标记标记 JS 问题。
标签: javascript reactjs jsx