Vue: Should get default value if perent send null in props.

Created on 22 Aug 2018  路  6Comments  路  Source: vuejs/vue

Version

2.5.17

Reproduction link

https://jsfiddle.net/j97btnex/35/

Steps to reproduce

Child component should use default value. When parent send null in props.

Parent

<child :data="some_data_that_give_null_value"
></child>

Child.

<script>
    export default {
        props: {
            data: {
                type: Number,
                default: 99,
            },
        },

        mounted() {
            console.log(data);
        },
    }
</script>

What is expected?


What is actually happening?


Most helpful comment

I imagine this would break quite a few things. If you want the default value, pass undefined instead.

All 6 comments

I imagine this would break quite a few things. If you want the default value, pass undefined instead.

As @KaelWD said...

@KaelWD Thanks, But How? Can you give me an example.

Just convert null values to undefined before you pass them into the prop, or just don't produce nullable values before this.

@KaelWD Thank you so much.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

finico picture finico  路  3Comments

gkiely picture gkiely  路  3Comments

fergaldoyle picture fergaldoyle  路  3Comments

paceband picture paceband  路  3Comments

aviggngyv picture aviggngyv  路  3Comments