cnu4/vue-codemirror-lite
소개
Lightweight Codemirror Component for Vue.js
개발 도구측정된 스타 증가
- in 24h
- 0
- in 7 days
- 0
- in 15 days
- -1
- in 1 month
- 기록 수집 중
서로 겹치는 기간의 순증가량이며 일별 합계가 아닙니다. 측정값이 없으면 비워 둡니다. 스타는 관심도를 나타내며 품질을 보장하지 않습니다.
README.md
OriginalVue-Codemirror-Lite
CodeMirror Component For Vue.js (support 1.x and 2.x).
Lightweight
By default (to optimise bundle size) all modes and addons are not included. To enable them, see Using Language Modes and Addons.
Demo
Live Demo: https://cnu4.github.io/vue-codemirror-lite
To run the demo locally, run
npm install && npm run dev
View demo in browser on JSFiddle
Installation
npm
npm install vue-codemirror-lite
// Install the plugin
var Vue = require('vue')
var VueCodeMirror = require('vue-codemirror-lite')
Vue.use(VueCodeMirror)
// Or use as component (ES6)
import Vue from 'vue'
import { codemirror } from 'vue-codemirror-lite'
export default {
components: {
codemirror
}
}
browser
Include in the page
<script src="https://unpkg.com/vue-codemirror-lite/dist/vuecodemirror.min.js"></script>
install into vue
Vue.use(VueCodeMirror)
or use as components
Vue.component('codemirror', VueCodeMirror.codemirror)
CodeMirror itself was built into vuecodemirror.min.js, get CodeMirror by
window.CodeMirror = VueCodeMirror.CodeMirror
View demo in browser on JSFiddle
Usage
Usage in Component
<!-- simple -->
<codemirror :value="code"></codemirror>
<!-- simple (with bindings in Vue1.x) -->
<codemirror :value.sync="code"></codemirror>
<!-- simple (with bindings in Vue2.x) -->
<codemirror v-model="code"></codemirror>
<!-- advanced -->
<codemirror
:value="code"
:options="editorOption"
ref="myEditor"
@change="yourCodeChangeMethod">
</codemirror>
export default {
data () {
return {
code: 'const str = "hello world"'
}
},
computed: {
editor() {
// get current editor object
return this.$refs.myEditor.editor
}
},
mounted() {
// use editor object...
this.editor.focus()
console.log('this is current editor object', this.editor)
}
}
Properties
valueStringthe editor valueoptionsObject (newValue)options passed to the CodeMirror instance
See the CodeMirror Configuration for the available options.
Using Language Modes and Addons
Several language modes are included with CodeMirror.
By default (to optimise bundle size) all modes and addons are not included. To enable:
- install
vue-codemirror-lite - require the language modes or addons after you require
vue-codemirror-liteitself (If use browser version, you need to include necessary script file of mode and addons. View demo in browser on JSFiddle) - set the mode option in the options object
<template>
<codemirror :options="{
mode: 'javascript',
extraKeys: {'Ctrl-Space': 'autocomplete'}
}"></codemirror>
</template>
<script>
import { codemirror } from 'vue-codemirror-lite'
require('codemirror/mode/javascript/javascript')
require('codemirror/mode/vue/vue')
require('codemirror/addon/hint/show-hint.js')
require('codemirror/addon/hint/show-hint.css')
require('codemirror/addon/hint/javascript-hint.js')
export default {
...
}
</script>
See the demo source which implement JavaScript and vue syntax highlighting and JavaScript hint addon.
See the CodeMirror Manual for the more modes and addons.
License
MIT
관련 프로젝트 살펴보기
불러오는 중…