Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/string/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在使用gatsby image和graphql获取图像时,我不断出错_Graphql_Gatsby - Fatal编程技术网

在使用gatsby image和graphql获取图像时,我不断出错

在使用gatsby image和graphql获取图像时,我不断出错,graphql,gatsby,Graphql,Gatsby,我正在尝试添加一个来自graphql的图像。这个问题我已经遇到过好几次了,最后总是幸运地得到解决 查询图像时,我得到以下响应: “path”参数必须是string、Buffer或URL类型之一。 接收类型未定义 代码如下: import React from 'react' import { Link, graphql, useStaticQuery, StaticQuery } from 'gatsby' import Img from 'gatsby-image' import './lon

我正在尝试添加一个来自graphql的图像。这个问题我已经遇到过好几次了,最后总是幸运地得到解决

查询图像时,我得到以下响应:

“path”参数必须是string、Buffer或URL类型之一。 接收类型未定义

代码如下:

import React from 'react'
import { Link, graphql, useStaticQuery, StaticQuery } from 'gatsby'
import Img from 'gatsby-image'
import './longCard.css';

const CardData = props => {

    const slug = props.slug;
    return (
        <StaticQuery
            query={
                graphql`
            query($slug: String) {
                sanityProduct(slug: {current: {eq: $slug}}) {
                    slug{ 
                        current
                    }
                    title
                    featured_image {
                        asset {
                            childImageSharp {
                                fixed {
                                    ...GatsbyImageSharpFixed
                                }
                            }
                        }
                    }
                }
            }
`}
            render={data => <LongCard />}
        />
    )
}

export default CardData

export const LongCard = ({ data }) => {
    return (
        <div className="long-card">
            <div className="long-card-inner">
                <Link to={data.sanityProduct.slug.current}>{data.sanityProduct.title}</Link>
                {/* Add image */}
                <Img fixed={data.featured_image.asset.childImageSharp.fixed} />
            </div>
        </div>

    )
}
从“React”导入React
从“gatsby”导入{Link,graphql,useStaticQuery,StaticQuery}
从“盖茨比图像”导入Img
导入“/longCard.css”;
const CardData=props=>{
常量段塞=道具段塞;
返回(
}
/>
)
}
导出默认卡片数据
导出常量LongCard=({data})=>{
返回(
{data.sanityProduct.title}
{/*添加图像*/}
)
}

我不需要ChildImageSharp部分,我认为这只是用于查询文件系统