Here we take the button component as an example
Father's page:
<view class="buttonGroup">
<buttonGroup bind:cancel="closeEditDialog"></buttonGroup>
</view>
fatherjs:
page({
data:{
showEdit:false
},
closeEditDialog(){
this.setData({
showEdit:false
})
}
}
Component buttonGroup page:
<view class="buttonGroup">
<view class="cancel" bindtap="cancelFn">取消</view>
<view class="sure">确定</view>
</view>
Component functions:
methods: {
cancelFn () {
this.triggerEvent('cancel')
},
}
Summarize:
Call the custom event cancel through tigerEvent to call the parent page function
Official website: Inter-component communication and events | WeChat open documents