Package Exports
- vue-codemirror
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (vue-codemirror) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Vue-Codemirror
Codemirror component for Vue.js(1.x ~ 2.x),本组件基于 Codemirror构建,支持Vue全版本使用,支持100+多种语言、分支语言、语法,支持多种代码高亮theme,并可以自行配置,可使用Vue-Codemirror快速轻易构建出多种丰富全面的web code editor,并以此基础多次开发WebIDE,欢迎加入前端技术交流群:288325802
Example
Use Setup
install vue-codemirror
npm install vue-codemirror --saveVue use
// import with ES6
import Vue from 'vue'
// ...
import CodeMirror from 'vue-codemirror'
// require with Webpack/Node.js
var Vue = require('vue')
// ...
var CodeMirror = require('vue-codemirror')
// use
Vue.use(CodeMirror)
// --------------------------------------
// or use with component(ES6)
import Vue from 'vue'
// ...
import { codemirror } from 'vue-codemirror'
// use
export default {
components: {
codemirror
}
}Use in components
<codemirror></codemirror>
<!-- component data bind(Vue.js1.X) -->
<codemirror :code.sync="code"></codemirror>
<!-- component config example 1(Vue.js1.X) -->
<codemirror :code.sync="code" :options="editorOption"></codemirror>
<!-- in vue.js2.X .once and .sync are deprecated, parent component needs to explicitly emit an event instead of relying on implicit binding -->
<codemirror :code="code" :options="editorOption" @changed="codeChange"></codemirror>// editorOption example:
export default {
data () {
return {
code: 'const a = 10',
editorOption: {
tabSize: 4,
mode: 'text/javascript',
theme: 'base16-dark',
lineNumbers: true,
line: true,
...
}
}
},
// if you use in vue2.X,parent component needs to explicitly emit an event instead of relying on implicit binding
methods: {
codeChange(newCode) {
console.log(newCode)
this.code = newCode
}
}
}
// editorOption mode types:
// string mode
mode: 'text/javascript'
// object mode
mode: {
name: 'javascript',
json: true
}<!-- component config example 2(Vue.js1.X) -->
<codemirror :code.sync="css" :options="{ tabSize: 2, mode: 'css' }"></codemirror>data () {
return {
css: '.class { display: block }'
}
}