Vue设计table中的身份证号加密显示

为了保护用户隐私,需要对身份证号中间进行加密,且需要考虑末尾带有X的情况

话不多少直接上代码,运用正则解决:

<el-table-column prop="idcard" label="身份证" width="180">
          <template slot-scope="scope">{{
            scope.row.idcard
              ? scope.row.idcard.replace(
                  /^(.{6})(?:\w+)(.{4})$/,
                  "\$1********\$2"
                )
              : ""
          }}</template>
</el-table-column>
posted @ 2022-12-08 09:31  我在吃大西瓜呢  阅读(289)  评论(0编辑  收藏  举报