首页 > 解决方案 > Nuxt apollo TypeError:无法读取未定义的属性“节点”

问题描述

我正在使用 NuxtJS Vue-apollo 从带有 CPT 的 WordPress 获取 GraphQL 数据。

NuxtJS 中有几个页面分别列出posts,CPT1CPT2. 如果我重新加载页面,我可以显示所有帖子。但是,如果我从列出postsCPT1或任何其他组合的页面转到,我会收到以下错误TypeError: Cannot read property 'nodes' of undefined

即使我回去,第一页也可以列出帖子,而所有其他页面都会出错。查询如下所示:

query queryPosts {
  posts {
    nodes {
      id
      title
      modified
      date
      slug
      uri
      featuredImage {
        node {
          id
          sourceUrl(size: THUMBNAIL)
          altText
        }
      }
    }
  }
}

和:

query queryCPT1 {
cpt1 {
    nodes {
      id
      title(format: RENDERED)
      uri
      problemer { <- this is an ACF field
        cardTitle
        cardImage {
          id
          sourceUrl(size: LARGE)
        }
      }
    }
  }
}

我已经尝试在页面上显示 JSON 数据原始数据,并且有效。但是,如果我尝试在结果 JSON 中指定任何内容,则会收到错误消息。

我怎样才能解决这个问题?

标签: graphqlnuxt.jsvue-apollo

解决方案


推荐阅读