父组件
<component ref="xponent" />
<script lang="ts" setup>
import { ref } from "vue";
const xponent = ref();
const download = async () => {
console.log(xponent)
xponent.value.download()
}
</script>
子组件核心方法,多个defineExpose对外暴露方法就行
import { defineExpose } from "vue";
const download = () => {
alert("下载")
}
defineExpose({
download
})
这篇博客探讨了Vue中父组件与子组件间的通信,通过`ref`属性实现子组件方法的调用。示例展示了如何在父组件中调用子组件的`download`方法进行异步文件下载,子组件通过`defineExpose`暴露出下载功能。
1344

被折叠的 条评论
为什么被折叠?



