前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >vue代码编辑器组件_vue activiti

vue代码编辑器组件_vue activiti

作者头像
全栈程序员站长
发布2022-09-21 11:08:40
1.2K0
发布2022-09-21 11:08:40
举报
文章被收录于专栏:全栈程序员必看

大家好,又见面了,我是你们的朋友全栈君。

vue-monaco-editor

Monaco Editor Vue Component

Based off React Monaco Editor

Setup

代码语言:javascript
复制

npm install vue-monaco-editor –save

Simple Vue Use

代码语言:javascript
复制

import MonacoEditor from ‘vue-monaco-editor’

// use in component

export default {

components: {

MonacoEditor

}

}

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

代码语言:javascript
复制

defaults: {

selectOnLineNumbers: true,

roundedSelection: false,

readOnly: false,

cursorStyle: ‘line’,

automaticLayout: false,

glyphMargin: true

}

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

代码语言:javascript
复制

<MonacoEditor

height=”600″

language=”typescript”

:code=”code”

:editorOptions=”options”

@mounted=”onMounted”

@codeChange=”onCodeChange”

>

</MonacoEditor>

Parent

代码语言:javascript
复制

module.exports = {

components: {

Monaco

},

data() {

return {

code: ‘// Type away! \n’,

options: {

selectOnLineNumbers: false

}

};

},

methods: {

onMounted(editor) {

this.editor = editor;

},

onCodeChange(editor) {

console.log(this.editor.getValue());

}

}

};

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:

代码语言:javascript
复制

const CopyWebpackPlugin = require(‘copy-webpack-plugin’);

module.exports = {

plugins: [

new CopyWebpackPlugin([

{

from: ‘node_modules/monaco-editor/min/vs’,

to: ‘vs’,

}

])

]

};

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

Dev Use

代码语言:javascript
复制
git clone [this repo] .
npm install
npm run dev

Edit src/App.vue

发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/170428.html原文链接:https://javaforall.cn

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • vue-monaco-editor
    • Setup
      • Simple Vue Use
        • Component Props
          • Editor Default Options
        • Component Events
          • Example
            • Webpack Use
              • Dev Use
              领券
              问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档