[Vuejs]-Slice input vue js

0👍

You may use VueJS Computed & Javascript Split function to achieve what you need.

Eg:

data: () => ({
  userInput: ''  // 08:33
}),
computed: {
  hours: function() {
    return this.userInput.split(":")[0]  // return 08
  },
  minutes: function() {
    return this.userInput.split(":")[1]  // return 33
  }
}

Computed method will listen to the change of userInput in this case. Meaning if the user key in 08:33, then decided to change to 08:44, the minutes will react and change to 44.

Leave a comment