type不要設定成number 設定成text
<el-input v-model="form.bankCard" type="text" style="width: 400px;" placeholder="請輸入銀行卡賬號" :maxlength="23"></el-input>
複製程式碼
watch實時監控
watch: {
['form.bankCard'](val) {
this.$nextTick(() => {
this.form.bankCard = val.replace(/\D/g,'').replace(/....(?!$)/g,'$& ');
});
}
}
複製程式碼