最新国产好看的视频,伊人天堂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)提示),本文通過(guò)實(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、話不多說(shuō),直接上圖

總結(jié)

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

相關(guān)文章

最新評(píng)論

平度市| 秦皇岛市| 松溪县| 同心县| 彰化市| 玉溪市| 包头市| 嘉峪关市| 固安县| 札达县| 雷山县| 东安县| 德安县| 永寿县| 安顺市| 丹阳市| 安乡县| 石渠县| 永康市| 舟山市| 石首市| 治多县| 关岭| 兖州市| 闻喜县| 永丰县| 巩义市| 天长市| 颍上县| 壶关县| 太原市| 五台县| 泽普县| 温宿县| 祁阳县| 佛冈县| 栖霞市| 永吉县| 石林| 抚州市| 凤山市|