一、安装
- npm install --save-dev vue2-ace-editor
二、引入组件
components: {
editor: require('vue2-ace-editor'),
},
三、在页面上设置<editor></editor>
<editor
v-model="resultData"
@init="editorInit"
lang="json"
:options="editorOptions"
theme="chrome"
width="100%"
height="700"
>
</editor>
四、设置editorInit方法
editorInit: function () {
require("brace/theme/chrome");
require("brace/ext/language_tools"); //language extension prerequsite...
require("brace/mode/yaml");
require("brace/mode/json");
require("brace/mode/less");
require("brace/snippets/json");
},
五、代码编辑器样式editorOptions,在data里面设置
editorOptions: {
// 设置代码编辑器的样式
enableBasicAutocompletion: true,
enableSnippets: true,
enableLiveAutocompletion: true,
tabSize: 2,
fontSize: 14,
showPrintMargin: false, //去除编辑器里的竖线
highlightActiveLine: false, // 高亮选中行
scrollPastEnd: 0.1, // 超出内容的滚动范围
},
参考:https://blog.youkuaiyun.com/weixin_44634366/article/details/105688344