The WeChat applet subcomponent calls the function method of the parent component/page

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

Guess you like

Origin blog.csdn.net/weixin_44383533/article/details/130689511