Change the rule of boolean casting for props #660
rcjiang
started this conversation in
RFC Discussions
Replies: 1 comment 3 replies
-
https://vuejs.org/guide/components/props.html#boolean-casting |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Summary
Currently, props with boolean type have special casting rules as follows:
<MyComponent disabled />
equivalent to<MyComponent :disabled="true" />
, this's right, I really agree with it.<MyComponent />
undefined
. This‘s OK.false
.Basic example
This example mainly demonstrates the behavior under the current rules.
CompA.vue:
CompB.vue:
App.vue:
Motivation
The current behavior does not comply with JavaScript, as in the previous instance:
<CompB v-bind="{}" />
not equivalent to<CompB v-bind="{ foo: undefined }" />
<CompB />
not equivalent to<CompB :foo="undefined" />
Destructive impact on wrap components. As in the previous instance, we can set a default value for prop “foo“ of CompB. Considering the following scenario, this issue becomes prominent.
If CompA is from a UI library, I define a customized CompB by wrap it.
The UI library update CompA and maintain compatibility( add a optional boolean prop named "bar", set default value true),then upgrade version.
I update the UI library, according to its update log, no destructive changes have been made. But my app is paralyzed, and this is hard to detect.
Beta Was this translation helpful? Give feedback.
All reactions