我的网站使用 nuxt3 和 vue3。但我在使用 onMounted 挂钩时遇到问题。
这是我的 vue 页面。
<script setup lang="ts">
import { onMounted } from '@vue/runtime-core';
onMounted(() => {
console.log('myheader mounted');
})
</script>
<template>
<h1>test</h1>
</template>
Run Code Online (Sandbox Code Playgroud)
我收到此错误:
[Vue warn]: onMounted is called when there is no active component instance to be associated with. Lifecycle injection APIs can only be used during execution of setup(). If you are using async setup(), make sure to register lifecycle hooks before the first await statement.
Run Code Online (Sandbox Code Playgroud)
让我很困惑……TT