As the title of the question, this
context is not available in the functional component. So if I have to emit an event, how can I do that?
For example in be
This is explained in the docs Passing Attributes and Events to Child Elements/Components:
If you are using template-based functional components, you will also have to manually add attributes and listeners. Since we have access to the individual context contents, we can use
data.attrs
to pass along any HTML attributes andlisteners
(the alias fordata.on
) to pass along any event listeners.
At the most basic level, you can delegate all listeners like this:
If you only want to bind the change
listener, you can do:
but this will fail if listeners.change
is undefined/null (not provided to the functional component).
If you need to handle the situation where there is no change
listener, then you can do this abomination:
{})">
otherwise you would have to settle by writing the render function by hand, since I don't think it is possible to conditionally assign the change
listener to
in the template of a functional component. (Or maybe you can? I'm not sure.)