有哪些可以做兼职的翻译网站,苏州网站建设优化过哦,广州品牌策划公司有哪些,婚纱摄影网站模板一#xff0c;ref
在父组件的模板里#xff0c;对子组件的标签定义ref属性#xff0c;并且设置属性值#xff0c;在方法里获取ref()获取实例对象。
父组件#xff1a;
templatediv div我是父组件/divSonCom refsonComRe…一ref
在父组件的模板里对子组件的标签定义ref属性并且设置属性值在方法里获取ref()获取实例对象。
父组件
templatediv div我是父组件/divSonCom refsonComRef/SonCom /div
/template
script setup langtsimport SonCom from /components/SonCom.vue; // 引入子组件import { ref } from vue;// 获取子组件实例let sonComRef ref() // 这里变量必须跟ref属性定义的值一致// 必须加载完成组件后再去获取实例onMounted(() {console.log(sonComRef.value.msg) // 我是暴露出去的子组件数据sonComRef.value.fun() // 我是暴露出去的子组件方法})
/script二defineExpose
子组件引入defineExpose在通过defineExpose暴露出去数据和方法
子组件
templatediv div我是子组件/div/div
/template
script setup langtsimport { ref defineExpose } from vue;let msg refstring(我是暴露出去的子组件数据)let fun () {console.log(我是暴露出去的子组件方法);}defineExpose({msg,fun})
/script