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)

.
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1be9e5f-319ab.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1be9e5f-319ab.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?