Nuxt.js: MetaInfo in layout

Created on 27 Jul 2017  路  6Comments  路  Source: nuxt/nuxt.js

Is it possible to get access to $metaInfo of current page in layout? It will be usefull to set page title (not title tag)

question

Most helpful comment

@clarkdo thanks! Tried and in layouts/default.vue $metaInfo is not defined

All 6 comments

Any news? :)

Sorry for the late reply, you can try 1.0.0 now:

export default {
  data() {
    return { meta: {title: 'abc'} }
  },
  head() {
    return {
      title: this.meta.title
    }
  },
  created() {
    console.log(this.$metaInfo.title) // read meataInfo
    this.meta.title = 'New Title' // set new title
  }
}

@clarkdo thanks! Tried and in layouts/default.vue $metaInfo is not defined

Same too, can not access $metaInfo in layouts/default.vue. $metaInfo is not defined

@canhkieu
Can you provide a repo ? I have tried below which works for me

<template>
  <div>
    <nuxt/>
  </div>
</template>

<script>
export default {
  data() {
    return { meta: {title: 'abc'} }
  },
  head() {
    return {
      title: this.meta.title
    }
  },
  created() {
    console.log(this.$metaInfo.title) // read meataInfo
    this.meta.title = 'New Title' // set new title
  }
}
</script>

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

shyamchandranmec picture shyamchandranmec  路  3Comments

o-alexandrov picture o-alexandrov  路  3Comments

vadimsg picture vadimsg  路  3Comments

bimohxh picture bimohxh  路  3Comments

gary149 picture gary149  路  3Comments