question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Defining `head` property in Nuxt

See original GitHub issue

As you probably know, in @nuxtjs/composition-api you must add an empty head: {} to use the useMeta composition function.

Maybe it’s going over my head but, is there any way at the moment to do this with <script setup>?

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

6reactions
antfucommented, Aug 22, 2021

<script setup> allow the co-existence with the normal <script>, meaning you can use this as a current workaround:

<script setup>
import { useMeta } from  '@nuxtjs/composition-api'

useMeta({ ... })
</script>

<script>
export default {
  head: {}
}
</script>

/cc @danielroe do you see if there is a way to by pass this limitation or we have to do that in compile time?

3reactions
yinfoyuancommented, Sep 27, 2021
<script lang="ts" setup>
import { useContext, useAsync, ref, useMeta, defineComponent } from '@nuxtjs/composition-api'

const { $axios } = useContext()

const fontUrl = ref<string>('')
const title = ref('a')

useAsync(async () => {
  title.value = 'b'
  fontUrl.value = await $axios.$get('/xxx')
})

useMeta(() => ({
  title: title.value
}))

</script>
<script lang="ts">
export default defineComponent({
  head: {}
})
</script>
import { defineComponent as defineComponent$1 } from '@nuxtjs/composition-api'

declare global {
  const defineComponent: typeof defineComponent$1
}

I worked it out for now

Read more comments on GitHub >

github_iconTop Results From Across the Web

The head Property - Nuxt
The head property. Nuxt let you define all default meta for your application inside nuxt.config.js , use the same head property ...
Read more >
SEO in Nuxt.js with the Head Property - DEV Community ‍ ‍
1) Use the nuxt.config. · 2) Add the head method as an object to your script tag in your page. This is a...
Read more >
API: The head Property - Nuxt.js
Nuxt.js let you define all default meta for your application inside nuxt.config.js.
Read more >
SEO and Meta · Get Started with Nuxt
Providing an app.head property in your nuxt.config.ts allows you to customize the head for your entire app. This method does not allow you...
Read more >
nuxt.js - How to get config head setting to set page og:title in ...
head property in the nuxt.config.js is for adding general head elements to all your pages. If you want to store a global configuration ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found