1、封装一个方法
formatPhone(val) {
if (val) {
let matches = /^(\d{3})(\d{4})(\d{4})$/.exec(val)
if (matches) {
val = matches[1] + ' ' + matches[2] + ' ' + matches[3]
}
}
return val
}
2、使用方法(示例代码如下)
res.data.phone = this.formatPhone(res.data.phone)
console.log(res.data.phone)