Ask Your Question
2

How do I pass the page title in Nuxt / Vue 3?

asked 2023-03-04 11:00:00 +0000

plato gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
3

answered 2022-01-27 10:00:00 +0000

ladyg gravatar image

In Nuxt, you can access the page title in the head object of your component file. You can set the title dynamically using Vue's computed properties.

Here's an example:

<template>
  <div>
    <h1>{{ greeting }}</h1>
  </div>
</template>

<script>
export default {
  computed: {
    greeting() {
      return 'Hello, world!'
    },
  },

  head() {
    return {
      title: this.greeting,
    }
  },
}
</script>

In this example, we set the title attribute of the head object to the value of the greeting computed property. This sets the page title to "Hello, world!"

You can also set other head attributes such as meta, base, link, script, and more. See the Nuxt documentation on the head method for more information.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2023-03-04 11:00:00 +0000

Seen: 20 times

Last updated: Jan 27 '22