vue 隔四个字符加一个空格
效果图
输入方式进行格式化
代码:
<el-form-item label="测试" prop="test"> <el-input v-model="queryParams.test" placeholder="测试" clearable :maxlength="23" size="small" /> </el-form-item>
watch监听
watch: { ['queryParams.test'](val) { this.$nextTick(() => { this.queryParams.test = val.replace(/\D/g,'').replace(/....(?!$)/g,'$& '); console.log('数字是多少:', this.queryParams.test,val) }); } },
展示直接格式化
{{ item.name.replace(/(\d{4})(?=\d)/g, '$1 ') }}
评论 (0)