项目作者: matt-oconnell

项目描述 :
Monaco Editor Vue Component
高级语言: Vue
项目地址: git://github.com/matt-oconnell/vue-monaco-editor.git
创建时间: 2016-12-22T18:58:01Z
项目社区:https://github.com/matt-oconnell/vue-monaco-editor

开源协议:MIT License

下载


vue-monaco-editor

!!!! This is not maintained !!!!

Monaco Editor Vue Component

Based off React Monaco Editor

experimental

Setup

  1. npm install vue-monaco-editor --save

Simple Vue Use

  1. import MonacoEditor from 'vue-monaco-editor'
  2. // use in component
  3. export default {
  4. components: {
  5. MonacoEditor
  6. }
  7. }

Component Props

Option Type Default Description
language String javascript
height Number/String 100%
width Number/String 100%
code String // code \n Initial code to show
theme String vs-dark vs, hc-black, or vs-dark
highlighted Array[Object] [{ number: 0, class: ''}] Lines to highlight with numbers and .classes
changeThrottle Number(ms) 0 throttle codeChange emit
srcPath String "" see Webpack Use below
editorOptions Object Merged with defaults below See Monaco Editor Options

Editor Default Options

  1. defaults: {
  2. selectOnLineNumbers: true,
  3. roundedSelection: false,
  4. readOnly: false,
  5. cursorStyle: 'line',
  6. automaticLayout: false,
  7. glyphMargin: true
  8. }

Component Events

These events are available to parent component

Event Returns Description
mounted editor[editor instance] Emitted when editor has mounted
codeChange editor[editor instance] Emitted when code has changed

Example

Component Implementation

  1. <MonacoEditor
  2. height="600"
  3. language="typescript"
  4. :code="code"
  5. :editorOptions="options"
  6. @mounted="onMounted"
  7. @codeChange="onCodeChange"
  8. >
  9. </MonacoEditor>

Parent

  1. module.exports = {
  2. components: {
  3. Monaco
  4. },
  5. data() {
  6. return {
  7. code: '// Type away! \n',
  8. options: {
  9. selectOnLineNumbers: false
  10. }
  11. };
  12. },
  13. methods: {
  14. onMounted(editor) {
  15. this.editor = editor;
  16. },
  17. onCodeChange(editor) {
  18. console.log(editor.getValue());
  19. }
  20. }
  21. };

Webpack Use

By default, monaco-editor is loaded from a cdn asyncronously using require. To use a local copy of monaco-editor with webpack, we need to expose the dependency in our build directory:

npm install copy-webpack-plugin --save-dev

Add this to your webpack.config.js:

  1. const CopyWebpackPlugin = require('copy-webpack-plugin');
  2. module.exports = {
  3. plugins: [
  4. new CopyWebpackPlugin([
  5. {
  6. from: 'node_modules/monaco-editor/min/vs',
  7. to: 'vs',
  8. }
  9. ])
  10. ]
  11. };

Then, specify the build directory path in the srcPath prop. See src/App.vue for an example.

Dev Use

  1. git clone [this repo] .
  2. npm install
  3. npm run dev

Edit src/App.vue