目前總結兩種方式實現,話不多說,直接上代碼。。。
1、通過substr()方法實現
1 <script> 2 export default { 3 data() { 4 return { 5 hideCode: '', 6 code: '232301222222228888' 7 } 8 }, 9 computed: { 10 11 }, 12 onLoad() { 13 this.hideCode = this.code.substr(0,6) + '********' + this.code.substr(14,17) 14 }, 15 methods: { 16 17 } 18 } 19 </script>
2、通過正則表達式實現
this.hideCode = this.code.replace(/^(\d{6})\d{8}(\d+)/,"$1********$2")
效果:

