NuxtJS+Graphql-一切都很好,但帖子标题没有显示在Template中



使用Nuxt+Strapi+Graphql,我试图在这里显示文章标题,下面是我的代码。没有任何错误,一切都很好,但帖子标题没有出现
如果您查看下面的Graphql查询,我成功地提取了Playground中的所有帖子信息。

知道出了什么问题吗?我应该如何访问对象?

<template>
<div>
<div v-for="post in posts" :key="post.slug">
<h1>{{ post.title }}</h1>
</div>
</div>
</template>
<script>
import { postQuery } from '~/graphql/query'
export default {
data() {
return {
posts: [],
}
},
apollo: {
posts: {
prefetch: true,
query: postQuery,
},
},
}
</script>
import gql from 'graphql-tag';
export const postQuery = gql`
query postQuery {
posts {
data {
attributes {
Title
DateTime
Content
IsAlgoAvailable
Slug
publishedAt
}
}
}
}
`

下面Graphql查询看起来不错

{
"data": {
"posts": {
"data": [
{
"attributes": {
"Title": "First Post Hello World",
"DateTime": "2022-10-02T16:02:00.000Z",
"Content": "First Hello World Content",
"Slug": "enter-title-here",
"publishedAt": "2022-10-03T13:20:47.359Z"
}
},
{
"attributes": {
"Title": "2nd Post",
"DateTime": "2022-10-02T16:01:00.000Z",
"Content": "Enter Content Here...",
"Slug": "2nd-post",
"publishedAt": "2022-10-03T14:34:44.140Z"
}
}
]
}
}
}

由于数据具有data.posts.data类型的结构,因此需要像一样对其进行循环

v-for="post in posts.data"

最新更新