Jammer
Jammer

Reputation: 10208

Nuxt Vanilla Site Body Attributes

I've looked all over the documentation and I cannot find a hint anywhere.

I want to add some default attributes and classes to my <body> tag for all pages.

Where can I set these?

Upvotes: 0

Views: 341

Answers (1)

Amirhossein Shahbazi
Amirhossein Shahbazi

Reputation: 1111

You can add attributes and classes to the body tag using the head method and bodyAttrs.

An example of using the head method:

export default {
  head () {
    return {
      bodyAttrs: {
        class: 'test-class',
        'data-test': 'some-attribute-data',
      }
    }
  },
}

If you want to add it to all the pages, include the code in your layout.

Upvotes: 3

Related Questions