@[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>