Default values for Vue component props & how to check if a user did not set the prop ?

Default values for Vue component props & how to check if a user did not set the prop ?

Asked on November 13, 2018 in vue.js.
Add Comment


  • 1 Answer(s)

    Vue allows for you to specify a default prop value and type directly, by making props an object

    props: {
        year: {
            default: 2016,
            type: Number
        }
    }
    

    If the wrong type is passed then it throws an error and logs it in the console

    Answered on November 13, 2018.
    Add Comment


  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.