在vue项目中使用codemirror插件实现代码编辑器功能

您所在的位置:网站首页 monaco编辑器 在vue项目中使用codemirror插件实现代码编辑器功能

在vue项目中使用codemirror插件实现代码编辑器功能

2023-01-05 19:42| 来源: 网络整理| 查看: 265

在vue项目中使用codemirror插件实现代码编辑器功能,在,vue,项,目中,使用,codemirror,插件,实现

在vue项目中使用codemirror插件实现代码编辑器功能

易采站长站,站长之家为您整理了在vue项目中使用codemirror插件实现代码编辑器功能的相关内容。

在vue项目中使用codemirror插件实现代码编辑器功能(代码高亮显示及自动提示),具体内容如下所示:

1、使用npm安装依赖

npm install --save codemirror;

2、在页面中放入如下代码

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/selection/active-line"); require("codemirror/mode/sql/sql"); require("codemirror/addon/hint/show-hint"); require("codemirror/addon/hint/sql-hint"); export default { name: "codeMirror", data () { return { code: '//按Ctrl键进行代码提示' } }, mounted () { debugger let mime = 'text/x-mariadb' //let theme = 'ambiance'//设置主题,不设置的会使用默认主题 let editor = CodeMirror.fromTextArea(this.$refs.mycode, { mode: mime,//选择对应代码编辑器的语言,我这边选的是数据库,根据个人情况自行设置即可 indentWithTabs: true, smartIndent: true, lineNumbers: true, matchBrackets: true, //theme: theme, // autofocus: true, extraKeys: {'Ctrl': 'autocomplete'},//自定义快捷键 hintOptions: {//自定义提示选项 tables: { users: ['name', 'score', 'birthDate'], countries: ['name', 'population', 'size'] } } }) //代码自动提示功能,记住使用cursorActivity事件不要使用change事件,这是一个坑,那样页面直接会卡死 editor.on('cursorActivity', function () { editor.showHint() }) } } .codesql { font-size: 11pt; font-family: Consolas, Menlo, Monaco, Lucida Console, Liberation Mono, DejaVu Sans Mono, Bitstream Vera Sans Mono, Courier New, monospace, serif; }

3、话不多说,直接上图

总结

以上所述是小编给大家介绍的在vue项目中使用codemirror插件实现代码编辑器功能,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对易采站长站网站的支持! 如果你觉得本文对你有帮助,欢迎转载,烦请注明出处,谢谢!

以上就是关于对在vue项目中使用codemirror插件实现代码编辑器功能的详细介绍。欢迎大家对在vue项目中使用codemirror插件实现代码编辑器功能内容提出宝贵意见



【本文地址】


今日新闻


推荐新闻


    CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3