How to Convert String into Integer using Vuejs, vuex?

13,693

You can use the .number modifier: https://vuejs.org/v2/guide/forms.html#number

<input v-model.number="bmw_quantity" type="number">
Share:
13,693
John Kohlmeier
Author by

John Kohlmeier

Updated on June 26, 2022

Comments

  • John Kohlmeier
    John Kohlmeier almost 2 years

    I have a Little Problem with my application. I am currently making a Basic stock Trader app (as an exercise). I am using Vuejs and Vuex. In my store.js file I am storing all the global variables but there is this problem with the bmw_quantity data. It is mapped to a v-model (Input field) which you can see in the stocks.vue component. For some reasons the data is always a string. I don't know why and I also tried several things but I couldn't convert the things I type in the field into an actual integer and not a string.

    Here is my code:

    image 1

    image 2

  • John Kohlmeier
    John Kohlmeier over 5 years
    Thank you very very much. I am quite knew to this (6 months) and still not knowing sooo much Things. You saved my evening. :)
  • sandrooco
    sandrooco over 5 years
    It‘s alright, that‘s why I‘m telling you. :) Please mark as solved when it works.
  • SriramK89
    SriramK89 over 4 years
    Dear @JohnKohlmeier... Please spare a few seconds to mark correct answer! Developers like me will feel easy to find such solutions.