小编KaM*_*Mui的帖子

使用 onMounted 钩子

我的网站使用 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

vue.js server-side-rendering nuxt.js vuejs3 nuxtjs3

7
推荐指数
1
解决办法
4万
查看次数

标签 统计

nuxt.js ×1

nuxtjs3 ×1

server-side-rendering ×1

vue.js ×1

vuejs3 ×1