fix(nuxt3): don't call lifecycle methods outside of component (#675)

This commit is contained in:
Daniel Roe 2021-10-06 19:58:57 +02:00 committed by GitHub
parent ac16127a13
commit 4b3814a14f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,5 +1,5 @@
import { createHead, renderHeadToString } from '@vueuse/head'
import { ref, watchEffect, onBeforeUnmount } from 'vue'
import { ref, watchEffect, onBeforeUnmount, getCurrentInstance } from 'vue'
import type { MetaObject } from '..'
import { defineNuxtPlugin } from '#app'
@ -18,6 +18,9 @@ export default defineNuxtPlugin((nuxt) => {
head.updateDOM()
})
const vm = getCurrentInstance()
if (!vm) { return }
onBeforeUnmount(() => {
head.removeHeadObjs(headObj)
head.updateDOM()