-
-
Notifications
You must be signed in to change notification settings - Fork 33.7k
Methods in functional components #8287
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
Conversation
merge latest
Supports the "methods" object in functional components for better functional-template usability re vuejs#8142
why |
@Kingwl I already explained in the PR body but, when using a render method instead of using a functional template, I can write functions outside of the component and reference them via closure. However, when using a template, I no longer have access to the closure. I can reference them via |
I respect your work, but I think there will be a better solution(maybe) |
I think that rather than having just methods, it will be useful to be able to inject stuff in the context so it can also be accessed in templates |
What are you thinking @Kingwl ? @posva If I've understood your suggestion correctly, that is what this PR is doing; it allows methods to be injected into the context so it can be accessed in the template. I'd like to see more support of functional components so that they can be easier to use and hence more useful; this will be a step towards that. Here's an issue in vue-loader (it was originally in vue but closed) that might explain the use-case more clearly: vuejs/vue-loader#1291 |
I don't think we should be going further along the route of "making functional components work like normal components in a Vue file", for the following reasons:
I think we should go back and make functional components more about "functions". |
What kind of change does this PR introduce? (check at least one)
Does this PR introduce a breaking change? (check one)
If yes, please describe the impact and migration path for existing applications:
The PR fulfills these requirements:
dev
branch for v2.x (or to a previous version branch), not themaster
branchfix #xxx[,#xxx]
, where "xxx" is the issue number)If adding a new feature, the PR's description includes:
Other information:
Currently it's difficult to use the functional template since you lose access to closures where as the render method can reference closed-over functions.