<el-input v-model="PJJFform.cpBankZh" @input="cpBankZhFormat()"></el-input>
methods:{
cpBankZhFormat:function () {
this.PJJFform.cpBankZh=this.PJJFform.cpBankZh.replace(/\s/g, '').replace(/[^\d]/g, '').replace(/(\d{4})(?=\d)/g, '$1 ')
}
}
效果图:
如果在后续接口传参数时,需要把空格去掉,就把对应字段进行如下处理:
this.PJJFform.cpBankZh=this.PJJFform.cpBankZh.trim().replace(/\s/g,"")