> 文章列表 > 微信小程序自定义组件:获取子组件实例对象,直接访问组件的任意数据和方法

微信小程序自定义组件:获取子组件实例对象,直接访问组件的任意数据和方法

微信小程序自定义组件:获取子组件实例对象,直接访问组件的任意数据和方法

前言

获取子组件实例对象

wxml

<myChildrenComponent id="mychildrenComponentId"
>
</myChildrenComponent>

js

let childrenComponent = this.selectComponent("#mychildrenComponentId")

访问组件方法

childrenComponent.fun1();

访问组件数据

childrenComponent.data.prop1