2

I have a vue project that needs to return data from a rich text field in Contentful. The data is returned as an object, is there a way to render this data using the v-html directive? At present I am able to render the html however it's wrapped in brackets, pictured below.

enter image description here

Code

  <div 
            v-if="testRich"

            class="mb4 testRich"

            v-html="testRich"
  />
Shawn
  • 219
  • 2
  • 10

1 Answers1

1

One option is to use filters, if you actually want the whole object

Vue.filter('jsonPretty', (value)=>{
  return JSON.stringify(value,null,4)
})

and then usage:

<div>{{testRich | jsonPretty}}</div>

If you just want the value you need to reference it correctly:

v-html="testRich.content[0].content[0].value"
depperm
  • 10,606
  • 4
  • 43
  • 67