父组件
ParentComponents.vue
<!-- 1. 在子组件上绑定ref -->
<children-component :ref="getChildList"></children-component>
...
<script>
import { ref } from 'vue'
export default {
setup () {
// 2、父组件中定义和ref同名的变量
const getChildList = ref(null)
onMounted (() => {
// 4、调用子组件中的getList()办法
console.log(getChildList.value.getList())
})
return {
// 3、return进来
getChildList
}
}
})
</script>
子组件
setup () {
// 办法
const getList = () => {
console.log('子组件中的办法')
}
return {
getList
}
}
发表回复