1

Rewritten this question as was not clear.

I am using Prismic and I've been able to pull blog posts on the page with prismic-javascript in my Nuxt project.

This is what I have at the moment:

  <section v-for="(post, i) in blogPosts" :key="i">
    {{ blogPosts[i].data.post_title[0].text }}
    {{ blogPosts[i].data.post_content[0].text }}
    <img :src="blogPosts[i].data.post_image.url" :width="blogPosts[i].data.post_image.dimensions.width">
  </section>

However, I am not sure how to drop a Prismic RichText render string into the v-for, like this one:

PrismicDOM.RichText.asHtml(blogPosts[i].data.post_content, linkResolver, htmlSerializer)

I am able to do that outside of the v-for, creating a variable, even if - and this might be a separate problem - I get all the html rendered as normal text, not tags.

I followed this "tutorial" but I am also not getting updated content from the blog despite the async/await (maybe I am missing something with this too)

Here's the rest of the code to get the posts:

async asyncData() {
const api = await Prismic.getApi(apiEndpoint, { accessToken: apiToken })
let blogPosts = {}
const response = await api.query(
  Prismic.Predicates.at('document.type', 'blog-post')
)
blogPosts = response.results
)
return {
  blogPosts
}

}

Thanks for your answers, hope it can also help / clarify it for others too.

Saro
  • 529
  • 1
  • 7
  • 19

1 Answers1

1

I think there is an error in the code. Can you update it and put this:

blog_post = results.results[0];
const header = PrismicDom.RichText.asText(blog_post.data.blog_post_title);
const content = PrismicDom.RichText.asText(blog_post.data.blog_content);

I tested it out, it should be working well!

  • I think I should've added the rest of the code (now added). I get all the blogPosts and correcty get all of them inside the v-for, but I don't know how can I apply the "PrismicDom.RichText" on the results inside the v-for. – Saro Mar 13 '19 at 12:01
  • Hi, article author here. I used this code to fix the issue. – Trevor-Indrek Lasn Mar 13 '19 at 16:30