登场文件:
父组件:定义多个按钮,每个按钮打开多个画面
子组件:是父Class的其中一个按钮
事件文件:想要通过某个事件实现从子调用父的某个Action
顺序:
1:新建一个Event文件
<aura:event type="APPLICATION" description="任意说明" />
2:在父组件里定义此事件关联的Action
<aura:handler name="CommonEvent" event="c:CommonEvent" action="{!c.handleClass}"/>
在父组件的Controller文件里里定义此Action的具体动作
handleClass : function(component, event, helper) {
任意操作!!
}
3:在子组件的Component文件里定义事件
<aura:registerEvent name="CommonEvent" type="c:CommonEvent"/>
在子组件的Helper文件里触发事件(实现调用父组件的方法)
var commonEvent = component.getEvent("CommonEvent");
commonEvent.fire();