mirror of
https://github.com/nuxt/nuxt.git
synced 2025-01-31 15:50:32 +00:00
fix: apply subsequent meta changes (#3271)
This commit is contained in:
parent
77aeaa3288
commit
ad52b795e2
@ -7,7 +7,12 @@ export default defineNuxtPlugin((nuxtApp) => {
|
|||||||
const head = createHead()
|
const head = createHead()
|
||||||
|
|
||||||
nuxtApp.vueApp.use(head)
|
nuxtApp.vueApp.use(head)
|
||||||
nuxtApp.hooks.hookOnce('app:mounted', () => { watchEffect(() => head.updateDOM()) })
|
|
||||||
|
let headReady = false
|
||||||
|
nuxtApp.hooks.hookOnce('app:mounted', () => {
|
||||||
|
watchEffect(() => { head.updateDOM() })
|
||||||
|
headReady = true
|
||||||
|
})
|
||||||
|
|
||||||
nuxtApp._useMeta = (meta: MetaObject) => {
|
nuxtApp._useMeta = (meta: MetaObject) => {
|
||||||
const headObj = ref(meta as any)
|
const headObj = ref(meta as any)
|
||||||
@ -15,11 +20,16 @@ export default defineNuxtPlugin((nuxtApp) => {
|
|||||||
|
|
||||||
if (process.server) { return }
|
if (process.server) { return }
|
||||||
|
|
||||||
|
if (headReady) {
|
||||||
|
watchEffect(() => { head.updateDOM() })
|
||||||
|
}
|
||||||
|
|
||||||
const vm = getCurrentInstance()
|
const vm = getCurrentInstance()
|
||||||
if (!vm) { return }
|
if (!vm) { return }
|
||||||
|
|
||||||
onBeforeUnmount(() => {
|
onBeforeUnmount(() => {
|
||||||
head.removeHeadObjs(headObj)
|
head.removeHeadObjs(headObj)
|
||||||
|
head.updateDOM()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user