Nuxt.js: tag BODY modification

Created on 1 Feb 2017  Â·  7Comments  Â·  Source: nuxt/nuxt.js

how to modify the tag BODY?
as described in the documentation https://github.com/declandewet/vue-meta
changes are not applied

This question is available on Nuxt.js community (#c158)

Most helpful comment

<script>
export default {
  head: {
    bodyAttrs: {
      class: 'home-page home page page-id-4 page-template page-template-template-homepage page-template-template-homepage-php'
    }
  }
}
</script>

Please read nuxt documentation

All 7 comments

I will need an example to help you.

On Wed, 1 Feb 2017 at 20:19, Oleg Bogdanov notifications@github.com wrote:

how to modify the tag BODY?
as described in the documentation https://github.com/declandewet/vue-meta
changes are not applied

—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/nuxt/nuxt.js/issues/188, or mute the thread
https://github.com/notifications/unsubscribe-auth/AA3OFOt9H9JOiBMriqp9M66UdwPd0_mtks5rYNrLgaJpZM4L0RX1
.

@Atinux

<body class="home-page home page page-id-4 page-template page-template-template-homepage page-template-template-homepage-php">
<script>
export default {
  head: {
    bodyAttrs: {
      class: 'home-page home page page-id-4 page-template page-template-template-homepage page-template-template-homepage-php'
    }
  }
}
</script>

Please read nuxt documentation

Hello ! This works perfectly thanks @Atinux :) However, i'm using some custom page transitions and while page elements are leaving, body classes are removed and replaced only when the new page is done :( There is a small moment where there is no classes at all. You know if there is a way to trigger bodyAttrs: { class } when transition done() is called ?

Thanks :+1:

@proov If you make that head parameter a function it becomes reactive, so whenever your data changes, the meta-data changes. E.g:

export default {
    data () {
        return {
            dataLoaded: false
        }
    },

    head () {
        return {
            bodyAttrs: {
                class: this.dataLoaded ? 'home-page home page page-id-4 page-template page-template-template-homepage page-template-template-homepage-php' : ''
            }
        }
    },

    // fetch data in some hook and set this.dataLoaded to true.
}

@Atinux you save my lot of time.. thanks :-)

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

vadimsg picture vadimsg  Â·  3Comments

mikekidder picture mikekidder  Â·  3Comments

bimohxh picture bimohxh  Â·  3Comments

surmon-china picture surmon-china  Â·  3Comments

nassimbenkirane picture nassimbenkirane  Â·  3Comments