文章目录

报错

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>
Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐