I have an input field that gets pre-populated from my DB, but I won't want it to be pre-filled if the value is 0
Eg:
<input v-model="price" type="text">
If
data: {
price: 0
}
I don't want my input field to display 0, I know that I can do stuff like :disabled="price == 0"
but this will hide the whole input field, I just don't want to display the value if its 0
To get an input value in Vue, we can use the v-model directive to set up a two-way binding between the value and a variable. Every time the user changes the text in the input field, the text variable will be updated automatically. We can then use this variable to perform an action or display information.
$v is an object that calls vuelidate (at the time of writing the comment, supported in version Vue.
The input value gets stored inside the variable and it never gets updated after that.
All you need to start off is basic knowledge of HTML, CSS, and JavaScript, of course. Vue doesn't require in-depth knowledge of libraries and additional technologies like JSX in React and TypeScript in Angular. All you need to start off is basic knowledge of HTML, CSS, and JavaScript, of course.
Simply change price to empty string when it's 0:
created() {
//since 0 is considered false it will put an empty string in case priceFromDB is 0
this.price = priceFromDB || ''
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With