效果如下:
具体实现如下:1
<input type="tel" class="phone" v-model="phoneText" @keydown="keyDown" @keyup.delete="keyUp" maxlength="13">
1 | keyDown (e) { // 按下时判断在指定位置添加空格 |
如果想要初始化赋值:1
2
3this.phoneText = this.phoneText
.replace(this.phoneText.substr(2, 1), this.phoneText.substr(2, 1) + ' ')
.replace(this.phoneText.substr(6, 1), this.phoneText.substr(6, 1) + ' ')