-
-
Notifications
You must be signed in to change notification settings - Fork 33.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Asset support for functional components #6872
Comments
Also, how to call methods and emit events in functional components with templates? |
You cannot, you use a regular component if you need that |
Support for local directives would be awesome! And @c01nd01r if you need to respond to an action, you can use plain old functions // event handler
function onClick(context, e) {
console.log('you clicked the div');
// to emit an event, look at the listeners in your context
if (context.listeners.click) {
context.listeners.click(e);
}
}
// component
export default {
functional: true,
render(h, context) {
return <div onClick={e => onClick(context, e)}>click me</div>;
},
}; |
Yes, @scottbedard, thank you. I know about this, but I can't do it in a "functional" html template. <template functional>
<div>
<button @click="$emit('click')">Emit click</button> <!-- error -->
<button @click="logClick">Log click</button> <!-- ??? -->
</div>
</template>
<script>
import { logClick } from 'logg';
</script> |
Yea, that would be great. Right now we can't really expose things to our template in a clean way. The only technique I thought of, was a prop with a default value. This works, but it looks terrible in my opinion, and unnecessary bloats the component's API. |
@yyx990803, are there any plans ahead about supporting local directives with functional components? It would allow, among others, to convert some more advanced components as functional where those features could be replaced by directives. I assume there are some technical limitations about it but would like to know if it's planned, what it requires, etc. So I can at least know why I must keep using normal components, for now. |
What is holding up the PR? It's been almost 4 months since it was opened. |
I would love to see this merged. |
Any further update on this improvement? |
It seems the PR is blocked since of conflicts in options interface. |
Do you have new news? |
This will likely never get approved. In v3, functional components are getting stripped of features even more in favor of stateful components supporting everything functional components can do; basically, you'll be able to update your functional component to be stateful and you'll rarely have a need for functional components in the future. Read the RFC here |
What problem does this feature solve?
Functional components with templates allow users to improve performance without sacrificing readability or ease of use. However, currently these do not support the "components" option. This limits this feature a lot, to a very limited set of use cases.
What does the proposed API look like?
Simply support the components option just like non-functional components
The text was updated successfully, but these errors were encountered: