DEV Community

Discussion on: 8 secrets Vue Developers must know

Collapse
 
avxkim profile image
Alexander Kim

In this example:

export default {
  functional: true,
  render(createElement, { listeners }) {
    return createElement(
      "button",
      {
        on: {
          click: event => {
            const emit_event = listeners.event_from_child;
            emit_event("Hello World!Is this the message we excpected? :/");
          }
        }
      },
      "Pass event to parent"
    );
  }
};

Don't forget to add condition to check, if emit actually requested from a functional component:

if (emit_event) emit_event("Hello World!Is this the message we excpected? :/");

Otherwise, if you won't listen to that emitted event, then you'll get an error.