Nuxt.js: Property for Layouts

Created on 16 May 2017  路  4Comments  路  Source: nuxt/nuxt.js

I have simple default Layout:

<template>
  <div class="simple">
    <h1 class="page-title">{{title}}</h1>
    <nuxt/>
  </div>
</template>

How to pass the value of the variable title from a certain page into a layout?

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

Most helpful comment

Sure, you can do this too :+1:

All 4 comments

@cawa-93 do you mean the title property comes from a page?

If so, you should use the vuex store for that.

@Atinux, You do not recommend using your example to pass a value from a page to a layouts? Something like this:
layouts/default.vue

<template>
<h1>{{title}}</h1>
</nuxt>
</template>

<script>
export default {
  computed: {
    title () {
      return this.$route.matched.map((r) => {
        return (r.components.default.options ? r.components.default.options.pageTitle : r.components.default.pageTitle)
      })[0]
    },
  },
}
</script>

pages/somePage.vue

export default {
  pageTitle: 'Title for H1 tag'
}

Sure, you can do this too :+1:

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

msudgh picture msudgh  路  3Comments

nassimbenkirane picture nassimbenkirane  路  3Comments

o-alexandrov picture o-alexandrov  路  3Comments

mattdharmon picture mattdharmon  路  3Comments

vadimsg picture vadimsg  路  3Comments