Original link: https://blog.rxliuli.com/p/f3564b039a28421188146aa89b52a3c0/
Scenes
Recently, other people in the group encapsulated some components based on antdv, and some boolean type props were transparently transmitted to antdv components. But in actual use, it is found that when these boolean props are not passed, the behavior of the antdv component is inconsistent with expectations.
question
For example
Component A
1 |
|
Component B
1 |
|
test use
1 |
|
rendering result
1 |
|
Does it feel amazing, component B clearly passes all props to component A, but it renders different results. Print the value of props.flag
in component B and find that it is false
. This is the actual problem.
solve
Well, the current solution is to force the default value of all boolean values to be undefined, for example
1 |
|
In this way, the expected result can be obtained.
1 |
|
refer to
- In the official documentation of vue, we found the definition of this behavior, ref: Boolean type conversion
- Checked vue issues and found that this is a question that has been raised since 2017. It seems to be a historical problem, ref: https://github.com/vuejs/vue/issues/4792
- There is a pr trying to change this behavior, ref: https://github.com/vuejs/core/pull/8602 .
This article is transferred from: https://blog.rxliuli.com/p/f3564b039a28421188146aa89b52a3c0/
This site is only for collection, and the copyright belongs to the original author.