How does Vue judge whether or not to transmit props according to the conditions?

<customeComponet
    :propA="needPropA ? dataA : null">
</customeComponet>



data () {
    return {
        dataA: {},
        needPropA: false
    }
}

the problem now is that when needPropA is not satisfied, there is no propA directly. Is there any other way to deal with it besides writing customComponent twice and then using v-if to control it?

Apr.07,2022

is right. The core of this problem lies not in whether passes prop , but in how to handle when a prop is not passed. The code posted by the landlord has been basically implemented. This logic is necessary for subcomponents because prop has a value, so the code must specify to accept the corresponding prop and do the processing. You just need to add compatible processing logic whose value is undefined/null .


Don't you judge


write a default value for the propA of the child component


you can put a calculation attribute there


it is equivalent to not passing undefined in vue, and the props parent components defined by the child component will be enumerated to (the value is undefined, just tested)

.
Menu