-
-
Notifications
You must be signed in to change notification settings - Fork 33.6k
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
warns when duplicated props from mixins #1431
Comments
Looks like this is because props are not properly de-duped when merged. However it seems a bad idea to have duplicate props in multiple mixins. I don't think this is the mixin mechanism's problem, but rather how you use mixins... IMO when you use multiple mixins, they should each serve a distinct purpose. If you have two mixins that have overlapping responsibilities then you probably need to rethink the design. |
Thanks, having duplicated props is actually a bad idea, I think I should remove the dep on |
Just curious. Imagine I have a mixin with some prop, I need to redefine its prop default value in component. How can I do it? |
@OEvgeny it will probably work like described in docs, not sure about props thought: http://rc.vuejs.org/guide/mixins.html#Option_Merging |
@OEvgeny that sounds like a bad idea to me. Ideally you don't want the sub fields of an option to be merged from multiple sources, especially when it is an object like a prop. It makes your code very hard to reason about. Hooks on the other hand makes more sense. |
@yyx990803 @azamat-sharapov thank you. I also think there is something wrong with my approach... :) |
Sometimes we would abstract some behaviours into mixins, for example:
A
,B
andC
. IfA
is mixed inB
andC
, and if theA
has a required prop nameda
, then when componentD
requiresB
andC
in mixins, vue will warn thea
is required even if a value passed toa
. Because one of the prop check fromB
orC
digests the value ofa
, leaving another one nothing.By the way, are there any suggestions to use / compose mixins? Because of the features of mixins, sometimes some implicit conflicts will raise up and not easy to find out. And in addition, the mixins require the component to obey some implicit interfaces, which lead to hard to maintain the codes.
The text was updated successfully, but these errors were encountered: