1.0.10 • Published 7 years ago

v-codemirror v1.0.10

Weekly downloads
42
License
-
Repository
-
Last release
7 years ago

Quick Start

If you use webpack, you need install css-loader and style-loader first:

npm install --save-dev css-loader style-loader

And add config in your webpack.config.js:

module.exports = {
  module: {
    rules: [
      {
        test: /\.css$/,
        use: [ 'style-loader', 'css-loader' ]
      }
    ]
  }
}

If you want to register V-Codemirror as a global component, you can use:

  import VCodemirror from 'v-codemirror' // default export is the install function
  Vue.use(VCodemirror)

Or If you don't want to pollute the global scope, you can register it when you want to use it:

  import {VCodemirror} from 'v-codemirror' // VCodemirror is a property in export object
  export default {
    name: 'app',
    components: {
      'V-Codemirror': VCodemirror
    }
  }  

A simple usage example as follows:

<template>
  <div class="simple-editor">
    <div class="editor">
      <V-Codemirror v-model="code" :options="editorOpts"></V-Codemirror>
    </div>
    <div class="preview">
      <pre v-html="code"></pre>
    </div>
  </div>
</template>

<script>
  import VCodemirror from 'v-codemirror'

  export default {
    components: {
      'V-Codemirror': VCodemirror
    },
    data () {
      return {
        code: '<h1>V-Codemirror</h1>',
        editorOpts: {
          mode: 'text/html'
        },
      }
    }
  }
</script>

API

props

NameRequiredTypeDescriptionDefault
v-modelNStringCode string value, It will work on two-way data binding, so you needn't watch the code value's change-
valueNStringCode string value, If you use value mode, you need to watch the value's change manually-
optionsNObjectEditor config, please move to codemirror-config to get detailed configuration list{tabSize: 2, mode: 'text/javascript', theme: 'monokai'}

Property v-model and value are forced alternative.

event

Some useful event are listed:

Event NameDescriptionCallback Value
changeFires every time the content of the editor content is changed.Current code string

The detailed event list and their docs can refer to codemirror-event

1.0.10

7 years ago

1.0.9

8 years ago

1.0.8

8 years ago

1.0.7

8 years ago

1.0.6

8 years ago

1.0.5

8 years ago

1.0.3

8 years ago

1.0.2

8 years ago

1.0.1

8 years ago

1.0.0

8 years ago