[Vuejs]-Conditionally add .trim modifier in Vue.js Input field

0👍

I dont think you can. I can however suggest a convenient computed property:

<input v-model="valueThatNeedsTrim" />
data() {
  return {
    valueFromData: "",
  }
},

computed() {
  valueThatNeedsTrim: {
    get() {
      return this.valueFromData
    },
    set(value) {
      this.valueFromData = value.trim()
    }
  }
}

Leave a comment