赞
踩
beautifyJson(json) { if (typeof json != 'string') { json = JSON.stringify(json, undefined, 2); } json = json.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replaceAll('{','{<br>').replaceAll('}','<br>}').replaceAll(',',',<br>'); return json.replace(/("(\\u[a-zA-Z0-9]{4}|\\[^u]|[^\\"])*"(\s*:)?|\b(true|false|null)\b|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?)/g, function (match) { let cls = 'number'; if (/^"/.test(match)) { if (/:$/.test(match)) { cls = 'key'; } else { cls = 'string'; } } else if (/true|false/.test(match)) { cls = 'boolean'; } else if (/null/.test(match)) { cls = 'null'; } return '<span class="' + cls + '">' + match + '</span>'; }); }
<style scoped> .line { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; } /deep/ .string { color: green; } /deep/ .number { color: darkorange; } /deep/ .boolean { color: blue; } /deep/ .null { color: magenta; } /deep/ .key { color: red; } </style>
<el-table-column label="参数" align="center" prop="params">
<template slot-scope="scope">
<el-tooltip class="item" effect="light" placement="top">
<div v-html="beautifyJson(scope.row.params)" slot="content" style="max-width:500px"></div>
<div class="line">{{scope.row.params}}</div>
</el-tooltip>
</template>
</el-table-column>
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。