微信小程序—组件通信—使用selectComponent获取组件实例

子组件component wxml

{{count}}

js

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()

},

推荐阅读

评论可见,请评论后查看内容,谢谢!!!
 您阅读本篇文章共花了: