mirror of
https://github.com/nuxt/nuxt.git
synced 2025-01-30 23:32:38 +00:00
fix(nuxt3): trigger update dom when invoking usemeta (#650)
This commit is contained in:
parent
1aa44209b4
commit
3fa75ba8a6
@ -1,5 +1,5 @@
|
|||||||
import { createHead, renderHeadToString } from '@vueuse/head'
|
import { createHead, renderHeadToString } from '@vueuse/head'
|
||||||
import { ref } from 'vue'
|
import { ref, watchEffect, onBeforeUnmount } from 'vue'
|
||||||
import type { MetaObject } from '..'
|
import type { MetaObject } from '..'
|
||||||
import { defineNuxtPlugin } from '#app'
|
import { defineNuxtPlugin } from '#app'
|
||||||
|
|
||||||
@ -8,7 +8,21 @@ export default defineNuxtPlugin((nuxt) => {
|
|||||||
|
|
||||||
nuxt.app.use(head)
|
nuxt.app.use(head)
|
||||||
|
|
||||||
nuxt._useMeta = (meta: MetaObject) => head.addHeadObjs(ref(meta as any))
|
nuxt._useMeta = (meta: MetaObject) => {
|
||||||
|
const headObj = ref(meta as any)
|
||||||
|
head.addHeadObjs(headObj)
|
||||||
|
|
||||||
|
if (process.server) { return }
|
||||||
|
|
||||||
|
watchEffect(() => {
|
||||||
|
head.updateDOM()
|
||||||
|
})
|
||||||
|
|
||||||
|
onBeforeUnmount(() => {
|
||||||
|
head.removeHeadObjs(headObj)
|
||||||
|
head.updateDOM()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
if (process.server) {
|
if (process.server) {
|
||||||
nuxt.ssrContext.renderMeta = () => renderHeadToString(head)
|
nuxt.ssrContext.renderMeta = () => renderHeadToString(head)
|
||||||
|
Loading…
Reference in New Issue
Block a user