Categories
Vue Answers

How to stop Vue.js from converting input[type=number] input value to a string value?

Spread the love

Sometimes, we want to stop Vue.js from converting input[type=number] input value to a string value.

In this article, we’ll look at how to stop Vue.js from converting input[type=number] input value to a string value.

How to stop Vue.js from converting input[type=number] input value to a string value?

To stop Vue.js from converting input[type=number] input value to a string value, we can add the number modifier to v-model.

For instance, we write

<template>
  <form>
    <input v-model.number="quantity" type="number" />
  </form>
</template>

to add the number modifier after v-model.

As a result, quantity would be a number instead of a string.

Conclusion

To stop Vue.js from converting input[type=number] input value to a string value, we can add the number modifier to v-model.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *