vue3.0父组件使用子组件里面的值以及调用子组件里面方法
html:
使用ref定义一个变量mychildExpertsConfiguration
<template>
<ExpertsConfiguration
ref="mychildExpertsConfiguration"
></ExpertsConfiguration>
</template>
js:
在js中定义一个与html中ref定义的一样的变量名mychildExpertsConfiguration进行绑定,然后mychildExpertsConfiguration.value就可以拿到子组件所有的值和方法了,mychildExpertsConfiguration.value?.XXX 可以获取子组件具体的值,mychildExpertsConfiguration.value?.XXX()去调用子组件的方法
import { ref,reactive,onMounted,onBeforeUnmount } from 'vue';
import ExpertsConfiguration from "../ExpertsConfiguration/ExpertsConfiguration.vue" //引用子组件
export default {
name: "GetMyTaskWaitingPageList",
setup() {
//获取子组件里面的提交方法
const mychildExpertsConfiguration = ref()
//在本页面中调用
const onSubmit= () => {
// console.log(mychildExpertsConfiguration.value,"所有子组件的值和方法")
mychildExpertsConfiguration.value?.onAssessSubmit && mychildExpertsConfiguration.value.onAssessSubmit()
}
onMounted(() => {})
return {
mychildExpertsConfiguration,
onSubmit
}
},
components: {
ExpertsConfiguration,
}
}