最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

在vue項(xiàng)目中使用codemirror插件實(shí)現(xiàn)代碼編輯器功能

 更新時(shí)間:2019年08月27日 14:06:52   作者:跌跌撞撞的博客  
這篇文章主要介紹了在vue項(xiàng)目中使用codemirror插件實(shí)現(xiàn)代碼編輯器功能(代碼高亮顯示及自動(dòng)提示),本文通過實(shí)例代碼給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下

在vue項(xiàng)目中使用codemirror插件實(shí)現(xiàn)代碼編輯器功能(代碼高亮顯示及自動(dòng)提示),具體內(nèi)容如下所示:

1、使用npm安裝依賴

npm install --save codemirror;

2、在頁(yè)面中放入如下代碼

<template>
 <textarea ref="mycode" class="codesql" v-model="code" style="height:200px;width:600px;"></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/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鍵進(jìn)行代碼提示'
   }
  },
  mounted () {
   debugger
   let mime = 'text/x-mariadb'
   //let theme = 'ambiance'//設(shè)置主題,不設(shè)置的會(huì)使用默認(rèn)主題
   let editor = CodeMirror.fromTextArea(this.$refs.mycode, {
    mode: mime,//選擇對(duì)應(yīng)代碼編輯器的語(yǔ)言,我這邊選的是數(shù)據(jù)庫(kù),根據(jù)個(gè)人情況自行設(shè)置即可
    indentWithTabs: true,
    smartIndent: true,
    lineNumbers: true,
    matchBrackets: true,
    //theme: theme,
    // autofocus: true,
    extraKeys: {'Ctrl': 'autocomplete'},//自定義快捷鍵
    hintOptions: {//自定義提示選項(xiàng)
     tables: {
      users: ['name', 'score', 'birthDate'],
      countries: ['name', 'population', 'size']
     }
    }
   })
   //代碼自動(dòng)提示功能,記住使用cursorActivity事件不要使用change事件,這是一個(gè)坑,那樣頁(yè)面直接會(huì)卡死
   editor.on('cursorActivity', function () {
    editor.showHint()
   })
  }
 }
</script>
<style>
.codesql {
  font-size: 11pt;
  font-family: Consolas, Menlo, Monaco, Lucida Console, Liberation Mono, DejaVu Sans Mono, Bitstream Vera Sans Mono, Courier New, monospace, serif;
 }
</style>

3、話不多說,直接上圖

總結(jié)

以上所述是小編給大家介紹的在vue項(xiàng)目中使用codemirror插件實(shí)現(xiàn)代碼編輯器功能,希望對(duì)大家有所幫助,如果大家有任何疑問請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!
如果你覺得本文對(duì)你有幫助,歡迎轉(zhuǎn)載,煩請(qǐng)注明出處,謝謝!

相關(guān)文章

最新評(píng)論

兴隆县| 璧山县| 筠连县| 运城市| 南投市| 武义县| 华容县| 彰武县| 阿鲁科尔沁旗| 姜堰市| 毕节市| 万山特区| 邮箱| 五大连池市| 三门峡市| 鲜城| 囊谦县| 绥中县| 正定县| 三台县| 光山县| 昭通市| 治县。| 浦北县| 邳州市| 新和县| 武义县| 米泉市| 长顺县| 郓城县| 大悟县| 南召县| 西昌市| 常宁市| 尼木县| 盱眙县| 石景山区| 三河市| 博客| 邵阳县| 乌恰县|