<input placeholder="填寫身份證號" v-model="id_card"/>
watch: {
['id_card'](val) {
this.$nextTick(() => {
this.id_card = val.replace(/\s/g,'').replace(/....(?!$)/g,'$& ');
});
}
}
這里用到了$&;這是Perl內置常量之一。
$& 是剛好匹配到的字符串 (之中)
$` 是匹配到字符串其余左邊的內容(之前)
$' 是匹配到字符串其余右邊的內容(之后)
