1.0.0 • Published 2 years ago

@wcfdehao/code-editor v1.0.0

Weekly downloads
-
License
MIT
Repository
-
Last release
2 years ago

code-editor

vue

npm

license

CodeMirror(6) component for Vue(3).

Usage

Install

npm install @wcfdehao/code-editor

local component

<template>
  <code-editor
    v-model="code"
    :dark="true"
    language="javascript"
  />

</template>

<script>
  import {ref} from 'vue'
  import { codeEditor } from '@wcfdehao/code-editor'

  export default {
    components: {
      codeEditor
    },
    setup() {
      const code = ref(`console.log('Hello, world!')`)

      return {
        code
      }
    }
  }
</script>

global component

import { createApp } from 'vue'
import App from './App.vue'
import CodeEditor from '@wcfdehao/code-editor'
createApp(App).use(CodeEditor, {
    dark:true,
    language:'python',
    tabSize: 2
}).mount('#app')

Component Props

propdescriptiontypedefault
modelValueinput value 双向绑定String''
readOnly是否只读,只读时编辑框禁止编辑,内容禁止更改。Booleanfalse
language编辑框的语言,默认支持,json,html,xml,python,javascript,markdownStringjson
dark编辑框深模式,使用的是 oneDark 主题Booleanfalse
tabSize编辑时一个tab键表示的空格数Number2
folded代码是否折叠BooleanFalse
fixedHeight编辑框的固定高度,表示像素。这个属性会被css覆盖。0表示根据内容自适应Number0
minHeight编辑框最小高度,表示像素。这个属性会被css覆盖。0表示根据内容自适应Number0
border编辑器边框样式,1px solid redString''

Component Events

eventdescriptionparams
update:modelValue当编辑框中的内容发生改变时触发(value: string, viewUpdate: ViewUpdate)
change同上同上
update当编辑框的任何状态发生改变时触发(viewUpdate: ViewUpdate)
focus当编辑框获取焦点时(viewUpdate: ViewUpdate)
blur当编辑框失去焦点时(viewUpdate: ViewUpdate)

License

Licensed under the MIT License.