npm run install monaco-editor
npm install --save-dev @babel/plugin-transform-class-static-block
module.exports = {
plugins: ["@babel/plugin-transform-class-static-block"],
};

<template>
<div style="width: 900px">
<div ref="codeContainer" class="coder-editor"></div>
</div>
</template>
<script>
import * as monaco from "monaco-editor";
export default {
name: "",
data() {
return {
msg: {
name: 12,
dep: "五车间",
hobby: {
eat: "Rice",
play: "Vscode",
},
},
monacoEditor: null,
};
},
mounted() {
this.init();
},
methods: {
init() {
if (this.$refs.codeContainer) {
this.monacoEditor = monaco.editor.create(this.$refs.codeContainer, {
value: "",
language: "javascript",
automaticLayout: true,
theme: "vs-dark",
minimap: {
enabled: false,
},
lineNumbers: "on",
foldingStrategy: "indentation",
overviewRulerBorder: false,
scrollbar: {
verticalScrollbarSize: 4,
horizontalScrollbarSize: 6,
},
readOnly: false,
cursorStyle: "line",
fontSize: 15,
tabSize: 2,
autoIndent: true,
});
}
this.monacoEditor.onDidChangeModelContent(() => {
console.log(this.monacoEditor.getValue());
});
},
},
};
</script>
<style lang="scss" scoped>
.coder-editor {
width: 100vw;
text-align: start;
height: 100vh;
border: 1px solid rgba(0, 0, 0, 0.08);
}
</style>