monaco-editor + vue 2

npm

https://www.npmjs.com/package/monaco-editor

api

https://microsoft.github.io/monaco-editor/api/index.html

使用

常用编辑器

<template>
	<div ref="container" class="editor"></div>
</template>
import * as monaco from "monaco-editor";
export default {
  data() {
    return {
      monacoEditor: {},
  },
  mounted() {
  	// 创建实例
  	this.monacoEditor = monaco.editor.create(this.$refs.container, {
      readOnly: false, // 只读
      language: "yaml", // 语言
      theme: "vs-dark", // 主题色
      wordWrap: "on", // 换行
      automaticLayout: true // 自动布局
    });
  }
}
配置字段(Interface IStandaloneEditorConstructionOptions)

https://microsoft.github.io/monaco-editor/api/interfaces/monaco.editor.IStandaloneEditorConstructionOptions.html

常用方法

// 监听文本改变事件
this.monacoEditor.onDidChangeModelContent((e) => {});

// 获取值
this.monacoEditor.getValue();

// 设置值
this.monacoEditor.setValue('content');

// 销毁
this.monacoEditor.dispose();

对比编辑器

this.monacoEditor = monaco.editor.createDiffEditor(this.$refs.container, {
  readOnly: true,
  language: "yaml",
  theme: "vs-dark",
  automaticLayout: true
});
this.monacoEditor.setModel({
  original: monaco.editor.createModel(this.originalContent, "yaml"),
  modified: monaco.editor.createModel(this.modifiedContent, "yaml")
});
配置字段(Interface IStandaloneDiffEditorConstructionOptions)

https://microsoft.github.io/monaco-editor/api/interfaces/monaco.editor.IStandaloneDiffEditorConstructionOptions.html

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值