vue
Learn how to use reactivity with Vue Unhead.
When using any of the provided composables, such as useHead
, full reactivity is provided out of the box.
All values are reactive and support:
const myPage = ref({ description: 'This is my page' })
const title = ref('title')
const myScript = computed(() => ({
src: 'https://example.com/script.js',
defer: true,
}))
useHead({
// ref (recommended)
title,
// computer getter (recommended)
meta: [{ name: 'description', content: () => myPage.value.description },],
// computed (not recommended)
script: [computed(() => ({
src: 'https://example.com/script.js',
defer: true,
}))],
})
It's recommended to avoid using computed
, as you will have simpler and more performant code.
When using reactivity in SSR, only at the time of rendering the SSR tags will be refs be resolved.
When using reactivity in CSR, any ref changes will trigger a request to update the DOM.