微信小程序—组件通信—使用selectComponent获取组件实例 子组件component wxml {{count}} js properties: {count:Number }, methods: {addCount(){
子组件component
wxml
{{count}}
properties: {count:Number }, methods: {addCount(){ this.setData({ count:this.properties.count+1 }) this.triggerEvent('sync',{value:this.properties.count})} }
一.通过父页面增加子组件的数据值
父页面page
wxml
{{count}}
js
data: {count:1 }, syncCount(e){this.setData({ count:e.detail.value}) }, getChild(){ const child = this.selectComponent('.childC') child.setData({ count:child.properties.count+1 }) },
二.通过父页面调用子组件的方法
getChild(){ const child = this.selectComponent('.childC')child.addCount() },
来源地址:https://blog.csdn.net/m0_48546501/article/details/129676894
--结束END--
本文标题: 微信小程序---组件通信---使用selectComponent获取组件实例
本文链接: https://www.lsjlt.com/news/373643.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-05-10
2024-05-10
2024-05-10
2024-05-10
2024-05-10
2024-05-10
2024-05-10
2024-05-10
2024-05-10
2024-05-10
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0