Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

NuxtJS + Graphql – Everything was well but the post title does not shows up in Template

With Nuxt + Strapi + Graphql, I’m trying to show the post title here and below is my code. No error and everything was well but the post title just didn’t show up.
If you look at the Graphql query below, I managed to pull out all those post information in Playground.

Any idea what went wrong? How should I access the object?

<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
        }
      }
    }
  }
`

Below Graphql query looking good

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

{
  "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"
          }
        }
      ]
    }
  }
}

>Solution :

Since the data had a data.posts.data kind of structure, you need to loop on it like

v-for="post in posts.data"
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading