- 在页面的wxml绑定自定义组件的id或者class(记得绑定组件哦)
<my-get-obj class="my_get_obj"/> <button bindtap="getObj">获取组件对象</button> - 在页面中调用this.selectComponent(组件的id或者类)
getObj(){ const cpn = this.selectComponent(".my_get_obj"); console.log(cpn); } - 然后修改组件对象中的数据有两种方式
- 通过获取的组件对象的setData方式修改组件对象中的数据(不推荐)
- 通过调用组件的中的方法修改组件对象中的数据(推荐)

1527

被折叠的 条评论
为什么被折叠?



