微信小程序—组件通信—使用selectComponent获取组件实例
•
移动开发
微信小程序—组件通信—使用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
<mytest count="{{count}}" bind:sync="syncCount" class="childC" id="cC">
{{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://www.net2asp.com/3f98470f5b.html
