JS在线代码编辑器多种方案monaco-editor,vue-monaco-editor
前言
JavaScript在线代码编辑器。
需要代码提示,关键字高亮,能够格式化代码。(不需要在线运行)
简简单单的需求。
源码地址:https://github.com/FannieGirl/vue-monaco-editor
方案一: Monaco-editor
简介:微软的开源项目,开源中国上面的在线代码编辑器也是用的这个(我就是顺着藤爬到Monaco editor的)
有 ‘在线 VS code’ 美称
官网:https://microsoft.github.io/monaco-editor/
优点:多语言支持,代码提示(内置函数蛮多的)。文档很清晰,API很详细了。更重要的是给出的案例非常多。
缺点:一开始摸不着头脑(本人是在vue项目使用),静态资源的引用是魔鬼(官方就是ES5方式资源引用),最好的方案是要搭配 webpack plugin 使用
找了那么多的资料,没见几个demo写的好(这也是我要再写一篇的原因啦 争取看到的人都可以快速上手)
源码:https://github.com/Microsoft/monaco-editor
案例:https://github.com/Microsoft/monaco-editor-samples/ 一定要看这个,官方给你展示各种功能(一套git pull 下来,在本地环境直接看demo),
鬼知道我走了多少冤枉路。
本人案例展示,直接上源码吗?哈哈哈。
npm install monaco-edtior //安装 test.vue //新建一个文件
<template>
<div ref="container" style="width:800px;height:600px;border:1px solid grey;text-align: left"></div>
</template> <script>
import * as monaco from "monaco-editor"; // 包体很大了 但是demo可以跑起来 export default{
mounted() {
var editor = monaco.editor.create(this.$refs.container, {
value: [
'function x() {',
'\tconsole.log("Hello world!");',
'}'
].join('\n'),
language: 'javascript',
minimap:{
enabled:false
},
selectOnLineNumbers: true,
roundedSelection: false,
cursorStyle: 'line', // 光标样式
automaticLayout: false, // 自动布局
glyphMargin: true, // 字形边缘
useTabStops: false,
fontSize: 16, // 字体大小
autoIndent: false //自动布局
});
}
}
</script>
JavaScript 参考这个案例!!!
方案二 vue-monaco-editor(没错就是别人集成好的)
原因:monaco 按需求加载太难了,官方案例也是在静态资源中引用 node_model中的(地狱来了)
针对这个有两种解决方案
方案一:资源引用哪家强,就到前端找webpack
方案二:本人偷懒,直接用vue-Monaco-editor(Rect 有的)
再次上源码,哈哈哈哈哈
方案一的源码
npm install monaco-editor-webpack-plugin //安装 const MonacoWebpackPlugin = require('monaco-editor-webpack-plugin'); module.exports = {
// ......
configureWebpack: {
plugins: [
new MonacoWebpackPlugin({
// available options are documented at https://github.com/Microsoft/monaco-editor-webpack-plugin#options
languages: ['javascript', 'css', 'html', 'typescript', 'json']
})
]
}
};
方案二的源码
<template>
<div id="app">
<MonacoEditor
height="300"
width="1200"
class="vs"
style="text-align: left;background-color: #fff"
language="javascript"
:code="code"
:editorOptions="options"
@mounted="onMounted"
@codeChange="onCodeChange"
>
</MonacoEditor>
</div>
</template> <script>
import MonacoEditor from 'vue-monaco-editor' export default {
data() {
return {
code: '',
editor:null,
options: {
theme: "vs",
selectOnLineNumbers: true,
roundedSelection: false,
readOnly: false,
automaticLayout: true,
glyphMargin: true,
showFoldingControls: "always",
formatOnPaste: true,
formatOnType: true,
folding: true,
}
}
},
components: {
MonacoEditor
},
methods:{
onMounted (editor) { this.editor = editor; }, onCodeChange(editor) {},
}
}
</script>
<style>
</style>
前方有坑
同一个项目里面
既安装了vue-monaco-editor 又安装了Monaco-editor
然后 就不会智能提示了(2333)
这个问题,emmm(稍后解决吧,我再搞codemirror的)
算了codeMirror 再分一篇文章
JS在线代码编辑器多种方案monaco-editor,vue-monaco-editor的更多相关文章
- Js的在线代码编辑器:CodeMirror
github地址:https://github.com/codemirror/CodeMirror/tree/master/demo 里面包含需要的js.css文件以及大量的示例 官网:https:/ ...
- (视频) 《快速创建网站》 3.2 WordPress多站点及Azure在线代码编辑器 - 扔掉你的ftp工具吧,修改代码全部云端搞定
本文是<快速创建网站>系列的第6篇,如果你还没有看过之前的内容,建议你点击以下目录中的章节先阅读其他内容再回到本文. 访问本系列目录,请点击:http://devopshub.cn/tag ...
- JS实现单例模式的多种方案
JS实现单例模式的多种方案 今天在复习设计模式中的-创建型模式,发现JS实现单例模式的方案有很多种,稍加总结了一下,列出了如下的6种方式与大家分享 大体上将内容分为了ES5(Function)与ES6 ...
- 20个最强的基于浏览器的在线代码编辑器 - OPEN资讯
20个最强的基于浏览器的在线代码编辑器 - OPEN资讯 20个最强的基于浏览器的在线代码编辑器
- ACE Editor在线代码编辑器简介及使用引导
转自博客:https://www.cnblogs.com/cz-xjw/p/6476179.html ACE 是一个开源的.独立的.基于浏览器的代码编辑器,可以嵌入到任何web页面或JavaScrip ...
- 在线代码编辑器CodeMirror简介
1.什么是Code Mirror 最近做一个项目需要在网页上实现一个代码编辑器,支持语法高亮.自动缩进.智能提示等功能.发现Code Mirror刚好满足所有需求.Code Mirror是由js写的一 ...
- CodeMirror在线代码编辑器使用
CodeMirror官网地址为:https://codemirror.net/ CodeMirror作为一款代码编辑器,其应用场景主要是在线网站写代码.如现在的leetcode.洛谷.code-vs等 ...
- 在线代码编辑器 Codemirror 的轻量级 React 组件
代码编辑器 CodeMirror 的轻量级 React 组件 demo @uiw-react.github.io/react-codemirror/ 特性:
- CodeMirror 在线代码编辑器
像百度编辑器插件部分.菜鸟教程示例等高德地图都在使用,这里也记录一下: CodeMirror是一个用于编辑器文本框textarea代码高亮javascript插件...... vue 中使用 参见:h ...
随机推荐
- [codeforces]Page Numbers <模拟>
描述: «Bersoft» company is working on a new version of its most popular text editor — Bord 2010. Bord, ...
- STM32F103ZET6通用定时器
1.通用定时器简介 通用定时器是由一个可编程预分频器驱动的16位自动装载计数器构成.通用定时器可以应用于多种场合,如测量输入信号的脉冲长度(输入捕获)或者产生输出波形(输出比较和PWM).使用通用定时 ...
- Codeforces - Watermelon
A. Watermelon time limit per test 1 second memory limit per test 64 megabytes input standard input o ...
- SpringCloud(一)之我学 Eureka
1.常用注册中心 1).zookeeper:高一致性(多个节点的数据保持一致): 2).eureka:高可用(系统不能访问的时间很少): 3).consul:上诉两个方案的折中. 高可用:消灭单点故障 ...
- 登录窗口java
这次代码是登录窗口的制作. 主要的方面是是包括,用户名.密码.验证码.以及输入数据所需要的文本框,对于验证码可以通过点击验证码进行修改.同时对于验证码的前景色和背景色同时都得到修改. 点击注册(这里还 ...
- 7L-双线链表实现
链表是基本的数据结构,尤其双向链表在应用中最为常见,LinkedList 就实现了双向链表.今天我们一起手写一个双向链表. 文中涉及的代码可访问 GitHub:https://github.com/U ...
- webstorm 永久激活方法
打开终端,执行: cd /etc/ sudo vim hosts 在最后一行加上: 0.0.0.0 account.jetbrains.com 打开webstorm,选择Activation Code ...
- android所有颜色
<?xml version="1.0" encoding="utf-8" ?> <resources> <color name=& ...
- PHP中debug基本方法
一.检查是否有语法错误 php -l test.php 二.基本调试基本调试 API: var_dump($var);print_r($var);echo $var; 基本的配置: display_e ...
- String 对象-->charAt() 方法
1.定义和用法 charAt() 方法获取指定下标的字符,下标从0开始 语法: string.charAt(index) 参数: index:指定的下标 举例:获取下标为2的字符 var str = ...