Method of calling parent component by Alipay applet sub component

Time:2021-4-7

In fact, it is a very simple requirement. When using a custom component, sometimes the child component needs to call the method of the parent component to perform some operations, such as updating data
But the official document is not very clear, so you can record it for the next time

//Subcomponent.axml
< button OnTap = "callfathercomponentmethod" > I am a subcomponent < / button >
//Subcomponent.js
methods:{
    callFatherCompoentMethod(){
        this.props.onCallFatherMethod()
        //Subcomponent calls are written in methods. Note that the function name must start with on
    }
}

//Parent component.json
{
    'child component': '// components / your child component path'
}
//Parent component.axml
<child-compoent onCallFatherMethod="fatherMethod" />
//Again, the calling function must be on the head
//Parent component.js
fatherMethod(){
console.log ('method of parent component called ')
}

OK is as simple as Vue’s custom component