7

I am creating my first SPA using Vue.js, Babel and WebPack. A Vue component has the following script:

<script>
export default {
  props: {
    name: String,
    required: true
  }
}
</script>

When I run eslint I get the following warnings and error:

8:5   warning  Prop 'name' requires default value to be set      vue/require-default-prop
9:5   warning  Prop 'required' requires default value to be set  vue/require-default-prop
9:15  error    The "required" property should be a constructor   vue/require-prop-type-constructor

I have copied the code from a tutorial I am following and I cannot understand how to fix it?

2 Answers 2

16

name should be an object,

<script>
export default {
  props: {
    name: {
      type: String,
      required: true
    }
  }
}
</script>
Sign up to request clarification or add additional context in comments.

Comments

2

I've got the issue and find the official document from https://eslint.vuejs.org/rules/require-default-prop.html This rule requires default value to be set for each props that are not marked as required (except Boolean props).

<script>
export default {
  props: {
    name: {
      type: String,
      required: true,
      default: "",
    }
  }
}
</script>

------example from https://eslint.vuejs.org/rules/require-default-prop.html

<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>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.