Geoff
Geoff

Reputation: 6639

nuxtjs modify head tags programmatically

In my page i have the following head body attributes

export default{
  head: {
     bodyAttrs: {
      class: 'parallax-visible'
      }
   },
   methods:{
    modifyHeadTags(){
      //here change the body class
      //eg set like this.head.bodyAttrs.class="newclass"
      console.log("head is", this.head); //this is undefined 
     }
  }

Now the above function logs the head is undefined, How do i modify these header tags programmatically

so in the function i expect to do something like

this.head.bodyAttrs.class = "new class" //this one

Upvotes: 0

Views: 774

Answers (1)

Helping hand
Helping hand

Reputation: 2920

head is available inside this.$options along with components, methods and other attributes in vueJs

You can access head using this.$options.head inside method function.

So you need to do something like this inside the function,

this.$options.head.bodyAttrs.class="newclass"  //make sure bodyAttrs is defined in head object

Upvotes: 1

Related Questions