JS.VUE.REQUIRE.DEFAULT.PROP

Require default value for props

Rule Details

This rule requires default value to be set for each props that are not marked as required (except Boolean props).

{'vue/require-default-prop': ['error']}

Copy
<script>
export default {
  props: {
    /* GOOD */
    a: {
      type: Number,
      required: true
    },
    b: {
      type: Number,
      default: 0
    },
    c: {
      type: Number,
      default: 0,
      required: false
    },
    d: {
      type: Boolean, // Boolean is the only type that doesn't require default
    },

    /* BAD */
    e: Number,
    f: [Number, String],
    g: [Boolean, Number],
    j: {
      type: Number
    },
    i: {
      type: Number,
      required: false
    }
  }
}
</script>

Options

Nothing.

Further Reading

  • Style guide - Prop definitions (https://vuejs.org/style-guide/rules-essential.html#use-detailed-prop-definitions)

The content on this page is adapted from the ESLint User Guide. Copyright © OpenJS Foundation and other contributors, www.openjsf.org. All rights reserved. https://eslint.org/docs/rules/