-
Install unhead import { createHead } from '@unhead/vue'
const head = createHead()
app.use(head) Comp.vue <script setup lang="ts">
import { onServerPrefetch } from 'vue'
import { getActiveHead } from 'unhead'
const head = getActiveHead()
onServerPrefetch(() => {
console.log(head) // undefined
})
</script> <script setup lang="ts">
import { onServerPrefetch } from 'vue'
import { injectHead } from '@unhead/vue'
const head = injectHead()
onServerPrefetch(() => {
console.log(head) // { plugins: [...], ... }
})
</script> The docs states: https://unhead.unjs.io/api/core/get-active-head But Is injectHead for Vue the way to go? |
Beta Was this translation helpful? Give feedback.
Answered by
harlan-zw
Jul 1, 2024
Replies: 1 comment
-
Hey, thanks for the discussion. If you're using Vue, you should always use This will likely break in v2 so better to stick to I'll leave this open as a reminder to improve the docs around this. |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
yooouuri
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey, thanks for the discussion.
If you're using Vue, you should always use
@unhead/vue
functions overunhead
functions. While usinggetActiveHead()
does work, it returns shared cross-request instance of unhead, whereinjectHead()
is bound to the Vue context.This will likely break in v2 so better to stick to
injectHead()
.I'll leave this open as a reminder to improve the docs around this.