Created
March 22, 2016 17:08
-
-
Save ricomonster/84b6a72a8ef45f0e65f7 to your computer and use it in GitHub Desktop.
Codemirror Directive for Vue JS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Should you not call
toTextArea()
inunbind
to clean up?