Monaco Editor for Vue.
npm install monaco-editor-vue<template>
<div id="app">
<MonacoEditor
width="800"
height="500"
theme="vs-dark"
language="javascript"
options={options}
@change="onChange"
></MonacoEditor>
</div>
</template>
<script>
import MonacoEditor from 'monaco-editor-vue';
export default {
name: "App",
components: {
MonacoEditor
},
data() {
return {
options: {
//Monaco Editor Options
}
}
},
methods: {
onChange(value) {
console.log(value);
}
}
};
</script>Add the Monaco Webpack plugin monaco-editor-webpack-plugin to your webpack.config.js:
const MonacoWebpackPlugin = require('monaco-editor-webpack-plugin');
module.exports = {
plugins: [
new MonacoWebpackPlugin({
// available options are documented at https://github.com/Microsoft/monaco-editor-webpack-plugin#options
languages: ['javascript']
})
]
};If you specify value property, the component behaves in controlled mode.
Otherwise, it behaves in uncontrolled mode.
widthwidth of editor. Defaults to100%.heightheight of editor. Defaults to100%.valuevalue of the auto created model in the editor.languagethe initial language of the auto created model in the editor. Defaults tojavascript.themethe theme of the editor. Defaults tovs.optionsrefer to Monaco interface IEditorConstructionOptions.change(newValue, event)an event emitted when the content of the current model has changed.editorBeforeMount(monaco)an event emitted before the editor mounted (similar tobeforeMountof Vue).editorMounted(editor, monaco)an event emitted when the editor has been mounted (similar tomountedof Vue).
Refer to Monaco interface IEditor.
Monaco only supports one theme.
<template>
<div id="app">
<MonacoEditor
:diffEditor="true"
original="..."
//...
></MonacoEditor>
</div>
</template>