-
-
Notifications
You must be signed in to change notification settings - Fork 33.8k
Closed
Description
What problem does this feature solve?
I have been recently making a Vue component library which has a dozen of props. There are two props called showCount
and showCountOnSearch
respectively. The props
property of my component looks like:
export default {
props: {
showCount: {
type: Boolean,
default: false,
},
showCountOnSearch: {
type: Boolean,
default: false,
},
// ...other props
},
// ...
}
I want the default value of showCountOnSearch
to be determined based on the value of showCount
. For example:
- When
showCount
is not specified, setshowCount
to the default valuefalse
. IfshowCountOnSearch
is not specified either, set it tofalse
too. - When
showCount
is specified andshowCountOnSearch
is not, setshowCountOnSearch
to the same value ofshowCount
.
In other words, showCountOnSearch
always defaults to the value of showCount
.
What does the proposed API look like?
Currently Vue allows default
property to be functions to generate default value dynamically. However, seems it's impossible to obtain another prop's value inside the default
function.
I hope the API to look like:
export default {
props: {
showCount: {
type: Boolean,
default: false,
},
showCountOnSearch: {
type: Boolean,
default(props) {
return props.showCount
},
},
// ...other props
},
// ...
}
thedamon, TitanFighter, pool13433, arlegotin, samehhashy and 2 more
Metadata
Metadata
Assignees
Labels
No labels