-
-
Notifications
You must be signed in to change notification settings - Fork 8.2k
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
Optional Props Declaration #26
Comments
Regarding TS users, they won't be able to use this, would they? |
@posva they can, with the For the runtime check, yes it is still dev only. |
Published: vuejs/rfcs#25 |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Summary
Make component
props
declaration optional.Basic example
Motivation
In simple use cases where there is no need for runtime props type checking (especially in functional components), making props optional could result in simpler code.
Detailed design
Stateful Components
When a component has no
props
declarations, all attributes passed by the parent are exposed inthis.$props
. Unlike declared props, they will NOT be exposed directly onthis
. In addition, in this casethis.$attrs
andthis.$props
will be pointing to the same object.Nice thing about this is you can omit the
<script>
block altogether in a simple SFC:Functional Components
This is based on plain-function functional components proposed in Functional and Async Component API Change.
To declare props for plain-function functional components, attach it to the function itself:
Similar to stateful components, when props are declared, the
props
arguments will only contain the declared props - attributes received but not declared as props will be in the 3rd argument (attrs
):For mode details on the new functional component signature, see Render Function API Change.
Drawbacks
N/A
Alternatives
N/A
Adoption strategy
The behavior is fully backwards compatible.
The text was updated successfully, but these errors were encountered: