Search code examples
javascriptvue.jsvuejs2nuxt.jsjson-ld

JSON-LD Schema NUXT


I am creating a Nuxt application powered by Wordpress.

I am receiving JSON-LD in my WP REST API via a schema plugin.Like so,

{
  wp_post_schema: "{"@context":"https://schema.org"}"
}

Below is how I use it in NUXT

head(){
    return {
        title: 'This is my page title',
        meta: [
            { hid: 'description', name: 'description', content: 'This is my description' }
        ],
        script: [
            {
                json: this.POST.wp_post_schema
                type: 'application/ld+json'
            }
        ],
    }
},
async asyncData({ $axios, req, params, query, error, route }) {
    var POST;
    try {
      let response = await $axios.get( "https://www.example.com/api);
      return {
        POST: response.data[0].post_meta_fields
      };
    } 
  }

My problem is that the JSON-LD rendered on the page is sanitized and is not recognised by google markup tool. Any suggestion on how i can effectively implement schema markup?


Solution

  • You should use a v-html to show the content more sanitize.

    <template>
      <script v-html="POST", type="application/ld+json">
    </template>