报错
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的格式文章来源:https://www.toymoban.com/news/detail-521740.html
解决
如果没有用到export
就需要用到语法糖
写法如下文章来源地址https://www.toymoban.com/news/detail-521740.html
<script setup lang="ts">
import {onMounted } from 'vue'
onMounted(()=>{
fetchData()
})
</script>
到了这里,关于【报错】onMounted is called when there is no active component instance too be associated with.的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!