vue3 <script setup>
中 子组件,获取父组件的数据
父组件
<template>
<div>
<slot/>
</div>
</template>
<script lang="ts" setup>
const props = defineProps({
type: {
type: String,
default: 10
}
})
</script>
子组件
<template>
<div>test</div>
</template>
<script lang="ts" setup>
import { getCurrentInstance } from "vue"
//获取父组件数据
const type = getCurrentInstance()?.parent?.props.type;
console.log(type)
</script>