父组件中循环子组件调用
父组件
//father.vue
<template>
<view>
<view v-for="(item,index) in list">
<son ref="son"></son>
</view>
<buton @click="submit">123</buton>
</view>
</template>
<script setup>
import {ref} from 'vue'
const son=ref(null)
const submit=()=>{
//通过循环调用想要调用的那个子组件
son.value.forEach(item=>{
item.getInfo()
})
}
</script>
子组件
//son.vue
<template>
<view>
<view v-for="(item,index) in list">
{{item.cd}}
</view>
</view>
</template>
<script setup>
const getInfo=()=>{
console.log('jwq');
}
defineExpose({getInfo})
</script>