I want to input while formatting the contents of input, for example, enter the bank card number, automatically four numbers space a space, the method has already been implemented, monitor input time for formatting, but this change to the background of the data into a space of data, I just want to change the display content, the actual preservation of the same, what should be done? After looking at the filter method on the Internet, I found that if I put it in v-model, I will report an error, and it is also the computer method, which doesn"t work.
<input name="bank_account" label="" placeholder=" " type="text" v-model="bank_account" @input="handleBankCardInput" :maxlength="23" />
handleBankCardInput(value) {
this.bank_account = value.replace(/\s/g, "").replace(/(\d{4})(?=\d)/g, "$1 ")
console.info(this.bank_account)
},
attempted computer method:
computed: {
bank_account: {
get() {
return this.bank_account.replace(/\s/g, ""())
// return this.bank_account.replace(/\s/g, ""())
},
set(val) {
this.bank_account = val.replace(/\s/g, "").replace(/(\d{4})(?=\d)/g, "$1 ")
}
}
}