1. Perform on() registration and.emit() execution through recursive traversal

// Register global methods
1.Prototype.$dispatch =function(eventName,data) { 
  this.$emit(eventName,data);
  let parent = this.$parent; 
  while(parent) { parent.$emit(eventName,data); parent = parent.$parent; }}2.Prototype.$boardcast =function(eventName,data) {
  boardcast.call(this,eventName,data);
}
function boardcast(eventName,data) {  
  this.$emit(eventName,data);
  this.$children.forEach(children= > {
    children.$emit(eventName,data);
    if(children.$children.length > 0){ boardcast.call(children,eventName,data); }}); }Copy the code