方法一:正则表达式
<el-table-column label="身份证号" :show-overflow-tooltip="true">
<template slot-scope="scope">
{{ scope.row.idCardNum.replace(/^(.{8})(?:\d+)(.{4})$/, '$1******$2') }}
</template>
</el-table-column>
其中8,4分别代表从第八位开始,剩余4位,大家可自行修改。
方法二:js代码处理
//str:要进行隐藏的变量 frontLen: 前面需要保留几位 endLen: 后面需要保留几位
function(str,frontLen,endLen) {
var len = str.length-frontLen-endLen;
var xing = '';
for (var i=0;i<len;i++) {
xing+='*';
}
return str.substring(0,frontLen)+xing+str.substring(str.length-endLen);
}