【报错】onMounted is called when there is no active component instance too be associated with.

简介: 【报错】onMounted is called when there is no active component instance too be associated with.

@[toc]

报错

onMounted is called when there is no active component instance too be associated with.Lifecycle injection APIs can only be used during execytion of setup(), If you are using async setup(),make sure to register lifecycle hooks before the first await statement.

分析

import {onMounted } from 'vue' 之后使用

onMounted(()=>{
   
    fetchData()
})

使用了Vue3的写法但并未遵从Vue3的格式

解决

如果没有用到export就需要用到语法糖
写法如下

<script setup lang="ts">
    import {
   onMounted } from 'vue'
    onMounted(()=>{
   
        fetchData()
    })
</script>
相关文章
|
7月前
|
JavaScript
Property “selectedItemIndex“ was accessed during render but is not defined on instance. 报错解决
Property “selectedItemIndex“ was accessed during render but is not defined on instance. 报错解决
714 0
|
7月前
|
NoSQL 编译器 API
关于thread使用的错误:pure virtual method called terminate called without an active exception
关于thread使用的错误:pure virtual method called terminate called without an active exception
161 1
|
3月前
|
JSON 前端开发 Java
template might not exist or might not be accessible by any of the configured Template Resolvers
template might not exist or might not be accessible by any of the configured Template Resolvers
126 0
|
4月前
|
Java Android开发
Invoke-customs are only supported starting with Android,Static interface methods are only supported
Invoke-customs are only supported starting with Android,Static interface methods are only supported
50 2
|
5月前
|
Web App开发 JavaScript
vue报错【解决方案】 [Violation] Added non-passive event listener to a scroll-blocking <some> event.
vue报错【解决方案】 [Violation] Added non-passive event listener to a scroll-blocking <some> event.
609 0
|
7月前
Error:Execution failed for task ':app:javaPreCompileDebug'. > Annotation processors must be explicit
Error:Execution failed for task ':app:javaPreCompileDebug'. > Annotation processors must be explicit
98 0
Unknown custom element: <add-employee> - did you register the component correctly? For red cursive c
原因: 1.组件名没写对(导入和注册不对应) 2.components少写了个s 3.组件命名最好是驼峰命名 4.导入时语法错误 5.代码中有两个components,后一个的值把前一个覆盖了 6.组件直接循环套用了
104 0
|
JavaScript
[Vue warn]: Unknown custom element: <Top> - did you register the component correctly?
[Vue warn]: Unknown custom element: <Top> - did you register the component correctly?