[Vuejs]-Errors: "[Vue warn]: Property or method "posts" is not defined on the instance but referenced during render." and also for "books"

0๐Ÿ‘

export default {

  components: {
    InstanceHeader,
    BooksInfoPostTop,
    BookTitles,
    BooksInfoPost
  },

  async asyncData(context) {
    const result = {};
    const mapBooks = b => {
      return {
        id: b.slug,
        bookCover: b.content.bookCover,
        title: b.content.title,
        author: b.content.author
      };
    };

    const { data } = await context.app.$storyapi
      .get("cdn/stories", {
        version: "draft",
        starts_with: 'books/book-titles'
      });

    result.posts = data.stories.map(mapBooks);

    const result = await context.app.$storyapi
      .get("cdn/stories", {
        version: "draft",
        starts_with: 'books/top-books'
      });

    result.books = result.data.stories.map(mapBooks);

    return result; // it has right property names {books:[], posts:[]}
  }
}

Well as you mentioned in the comment it was a little mess before. So i tidied it up. The idea is that you need direct property names instead of nested objects. This way it should work, if it is not working check the network tab for the errors.

Leave a comment