npm install --save highlight.js
npm install --save @highlightjs/vue-plugin
<template>
<highlightjs
autodetect
:code="jsonCode"
/>
</template>
<script>
import 'highlight.js/styles/stackoverflow-light.css';
import 'highlight.js/lib/common';
import hljsVuePlugin from "@highlightjs/vue-plugin";
export default {
setup() {
const jsonStr = [
{ 'name': 'JSON', 'address': '北京市西城区', 'age': 25 },
{ 'name': 'JSON', 'address': '北京市西城区', 'age': 25 }
];
let jsonCode = JSON.stringify(jsonStr, null, 2);
return {
jsonCode,
};
},
components: {
highlightjs: hljsVuePlugin.component
}
}
</script>