vue3+taro里面怎么使用selectComponent在父组件里面访问自组件的函数呢?
我试着使用
import { getCurrentInstance } from '@tarojs/taro'
const { page } = getCurrentInstance()
page.selectComponent('#mychart-dom-area')
但是效果没有出来访问不到子组件
然后又用了ref
<child ref="child"/>
const child=ref();
child.value.子组件的函数
也没有成功
扫描二维码关注公众号,回复:
14859171 查看本文章
最后使用的defineExpose把子组件暴漏出去,然后父组件使用ref的方法获取到
子组件
<script setup>
defineExpose({
showCanvasRing,
});
</script>
父组件
<child ref="child"/>
const child=ref();
child.value.showCanvasRing()