在vue项⽬中使⽤codemirror插件实现代码编辑器功能(代码⾼亮显⽰及⾃动提
⽰
run的过去式
在vue项⽬中使⽤codemirror插件实现代码编辑器功能(代码⾼亮显⽰及⾃动提⽰)
1、使⽤npm安装依赖
npm install --save codemirror;
2、在页⾯中放⼊如下代码走遍美国中英字幕
<template>
<textarea ref="mycode" class="codesql" v-model="code" ></textarea>
</template>
和老外聊天<script>
import "codemirror/theme/ambiance.css";
import "codemirror/lib/codemirror.css";
import "codemirror/addon/hint/show-hint.css";
let CodeMirror = require("codemirror/lib/codemirror");
require("codemirror/addon/edit/matchbrackets");
require("codemirror/addon/lection/active-line");
require("codemirror/mode/sql/sql");
require("codemirror/addon/hint/show-hint");
require("codemirror/addon/hint/sql-hint");
export default {
kelly huname: "codeMirror",
data () {
return {
code: '//按Ctrl键进⾏代码提⽰'
}
},
mounted () {
debugger
let mime = 'text/x-mariadb'
//let theme = 'ambiance'//设置主题,不设置的会使⽤默认主题
let editor = CodeMirror.fromTextArea(this.$de, {
mode: mime,//选择对应代码编辑器的语⾔,我这边选的是数据库,根据个⼈情况⾃⾏设置即可
indentWithTabs: true,
smartIndent: true,komatsu
lineNumbers: true,奥运英语
matchBrackets: true,
//theme: theme,
// autofocus: true,
extraKeys: {'Ctrl': 'autocomplete'},//⾃定义快捷键
hintOptions: {//⾃定义提⽰选项
tables: {
urs: ['name', 'score', 'birthDate'],
传宗接代英文
countries: ['name', 'population', 'size']
培训评估}
}
})
拜登提名总统候选人//代码⾃动提⽰功能,记住使⽤cursorActivity事件不要使⽤change事件,这是⼀个坑,那样页⾯直接会卡死
<('cursorActivity', function () {
editor.showHint()
})
}
}
</script>
<style>
font-size: 11pt;
font-family: Consolas, Menlo, Monaco, Lucida Console, Liberation Mono, DejaVu Sans Mono, Bitstream Vera Sans Mono, Courier New, monospace, rif;
}
</style>
3、话不多说,直接上图
4、这样就把代码编辑器实现啦,是不是so easy啊,你们⾃⼰去尝试下吧另⼀篇⽂章:使⽤Vue-codemirror使⽤总结