Vue-Codemirror代码块编辑器的使用方法

1.NPM

npm install vue-codemirror --save

2.官方地址

https://www.npmjs.com/package/vue-codemirror

3.页面引入和使用方法

有多种语言,我选择的是python主题

3.1 html

<codemirror @blur="inputChange($event)" v-model="defaultPocVal" :options="options"></codemirror>

3.2 引入

import { codemirror } from 'vue-codemirror'
import 'codemirror/mode/python/python.js'
import'codemirror/addon/selection/active-line.js'
import'codemirror/addon/edit/closebrackets.js'
import 'codemirror/lib/codemirror.css'
import 'codemirror/theme/base16-light.css'

3.3 dom

data() {
      return {
        pocVal: null,
        options: {
          autoCloseBrackets: true,
          tabSize: 4, // 缩进格式
          theme: 'base16-light', // 指定主题,js 需要提前引入
          lineNumbers: true, // 是否显示行号
          //指定语言类型,如果需要编辑和显示其他语言,需要import语言js然后修改此配置
          mode: 'python',
          line: true,
          styleActiveLine: true, // 高亮选中行
          //是否为只读,如果为"nocursor" 不仅仅为只读 连光标都无法在区域聚焦
          readOnly: false,
          hintOptions: {
            completeSingle: true // 当匹配只有一项的时候是否自动补全
          }
        },
        defaultPocVal: '',
    }
} 
inputChange(e) {
    let getChangeVal = e.getValue();//获取值
    this.pocVal = getChangeVal; //赋值
    this.validPocChange() //校验功能-根据自己的需求进行校验,此处就不详细写了
},

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值