vue父組件調用子組件的方法,獲取同步(實時)的返回結果

vue父組件調用子組件的方法,獲取同步(實時)的返回結果

//父組件

<template>
   <Child ref="childRef">
</template>

<script>
import Child from '.Child.vue'
components:{
  Child,
}
setup(props,ctx){

const childRef=ref()
//調用子組件的方法 const getChildValue
=()=>{ childRef.value.handlerSelectConfirm().then(selectData=>{ //得到返回值 }) } return { childRef, getChildValue } } </script>

 

子組件

//子組件

<template>
</template>

<script>

setup(props,ctx){
const chooseData= ref([])


const handlerSelectConfirm=async()=>{
  return new Promise((resolve,reject)=>{
    //返回結果
    resolve(chooseData.value)
  })
}

return {
  chooseData,
  handlerSelectConfirm,
}


</script>

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章