Skip to content

Instantly share code, notes, and snippets.

@ricomonster
Created March 22, 2016 17:08
Show Gist options
  • Save ricomonster/84b6a72a8ef45f0e65f7 to your computer and use it in GitHub Desktop.
Save ricomonster/84b6a72a8ef45f0e65f7 to your computer and use it in GitHub Desktop.
Codemirror Directive for Vue JS
Vue.directive('codemirror', {
twoWay : true,
bind : function () {
this.codemirror = CodeMirror(this.el, {
mode : "markdown",
tabMode : "indent",
lineWrapping : !0
});
this.codemirror.on("change", function () {
this.set(this.codemirror.getValue());
}.bind(this));
},
update: function (value, oldValue) {
this.codemirror.setValue(value || '');
}
});
// show it in the template!
<div v-codemirror="post.content"></div>
@texelate
Copy link

Should you not call toTextArea() in unbind to clean up?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment