Reputation: 1034
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?
Upvotes: 6
Views: 12851
Reputation: 988
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>
Upvotes: 2
Reputation: 2039
name should be an object,
<script>
export default {
props: {
name: {
type: String,
required: true
}
}
}
</script>
Upvotes: 15