fix: Formatted display of json content type(Compatible with illegal json)

This commit is contained in:
wuwen 2023-01-16 18:45:08 +08:00
parent f9f81ff560
commit cd16c1322d

View File

@ -23,9 +23,7 @@ limitations under the License. -->
class="content mb-10"
:readonly="true"
v-else-if="item.label === 'content'"
:value="
currentLog.contentType === 'JSON' ? formatJson(JSON.parse(currentLog[item.label])) : currentLog[item.label]
"
:value="contentFormat(item.label)"
/>
<span v-else-if="item.label === 'tags'" class="g-sm-8 mb-10">
<div v-for="(d, index) in logTags" :key="index">{{ d }}</div>
@ -56,6 +54,16 @@ limitations under the License. -->
return `${d.key} = ${d.value}`;
});
});
function contentFormat(label: string) {
try {
return props.currentLog.contentType === "JSON"
? formatJson(JSON.parse(props.currentLog[label]))
: props.currentLog[label];
} catch (e) {
return props.currentLog[label];
}
}
</script>
<style lang="scss" scoped>
.content {