I have a reusable input component that is being used in various places.
Everything works well with the number input, but the issue arises when I completely clear the input. This action triggers a warning message in the console:
[Vue warn]: Invalid prop: type check failed for prop "value". Expected Number with value 0, got String with value "".
found in
---> <Numberinput> at components/utilities/numberinput.vue
<Createproplayout> at components/layout/createproplayout.vue
<Pages/property/create.vue> at pages/property/create.vue
<Nuxt>
<Layouts/form.vue> at layouts/form.vue
<Root>
My code snippet is shown below:
Here is my reusable input component:
<template>
<div class="normal-form">
<!-- number input -->
<input
type="number"
:name="name"
:placeholder="placeholder"
:value="value"
@input="$emit('input', $event.target.value) ">
</div>
</template>
<script>
export default {
props: {
name: {
type: String,
required: true
},
placeholder: {
type: String,
required: false,
default: "text goes here"
},
value: {
type: Number,
}
}
}
</script>
Usage example:
<numberinput placeholder="xxx" name="price" v-model.number="form.price.amount">Amount </numberinput>
data() {
return {
form: {
price: {
currency: 'NGN',
amount: null,
}
},
}
},
https://i.sstatic.net/5C7o4.png Here is how it appears after entering a number and then clearing the input field.