Vue


父组件中执行子组件方法

父组件:
<template>
    <button @click="use">aaaaaaaaa</button>
    <SubDisplay ref="useChildMethod"></SubDisplay>
</template>
<script setup lang="ts">
    import { ref } from "vue";
    import SubDisplay from "../components/SubDisplay.vue";

    const useChildMethod = ref(null);
    function use() {
        useChildMethod.value.test();
    }
</script>
子组件:
<script setup lang="ts">
    import { defineExpose } from "vue";
    function test() {
        console.log('父组件调用了子组件方法')
    }
    defineExpose({ test })
</script>

页面列表

ITEM_HTML