-
-
Notifications
You must be signed in to change notification settings - Fork 33.7k
When prop's type is plain object, it's wonderful to merge default object and prop object when they all exist #6556
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
Comments
When the parent component passes prop to the child component, if the prop is a plain object, and the child component's default value build function also returns a plain object, we should shadow merge the default object and the prop object and add watcher. BREAKING CHANGE: Now when the default value and giving value are both plain object, they will merge with the first level. vuejs#6556
…necessary): code enhancement vuejs#6556
I tried to realized this feature at: My forked branch |
Unfortunately this will be a breaking change, so unlikely to happen :/ |
why closing a feature request only because causes a breaking change? a feature that merges props it's actually super nice and it's something that I have to do manually every time because it's a very common scenario when creating complex components. @yyx990803 Besides my point on the "closed ticket", could you suggest an elegant and reusable way to achieve this kind of behavior? I could maybe write a plugin :) Thanks for your time |
@MatteoGabriele and @ulivz , I agree with everyone who says that this should be the behavior. Just because I want to override one attribute/property, I should not mean that I have to provide all the other properties.
In the above case, I want to be able to override the labels. |
@yyx990803 in the light of Vue.js 3 can we please reconsider this option ? |
What problem does this feature solve?
When the parent component passes prop to the child component if the prop type is object, and its value has been given as a
plain object
, at the same time, and the child component's default value build function also returns aplain object
, we should merge the default object and the prop object (shadow merge
), which is very conducive to customize the default value. and also greatly enhance the feel of writing Vue components.A simple example:
In correct version, the
options
in child component will be rendered as:but the ideal result should be:
For performance reasons, we just need to do
shadow merge
.It will greatly enhance the writing feeling for some flexible and largely configurable component.
What does the proposed API look like?
No need new API, just handle in the logic of
check default value
The text was updated successfully, but these errors were encountered: