A Pen by Michael Garten on CodePen.
Created
August 22, 2018 20:37
-
-
Save mjgartendev/06261627a88f0c818fd5c8faddc351eb to your computer and use it in GitHub Desktop.
Vue and Codemirror Example
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
<html lang="en"> | |
<head> | |
<!-- Required meta tags always come first --> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1"> | |
<meta http-equiv="x-ua-compatible" content="ie=edge"> | |
</head> | |
<body> | |
<div class="container-fluid" id="app"> | |
<h1>CodeMirror + Vue</h1> | |
<div class="row"> | |
<div class="col-sm-6"> | |
<div class="card card-block editor-panel"> | |
<h3 class="card-title">Editor Panel</h3> | |
<textarea id="editor"><button class="btn btn-success btn-lg">Demo Button</button> | |
</textarea> | |
</div> | |
</div> | |
<div class="col-sm-6"> | |
<div class="card card-block editor-panel"> | |
<h3 class="card-title">Preview Panel</h3> | |
<p v-html="model.text"></p> | |
</div> | |
</div> | |
</div> | |
</div> | |
</body> | |
</html> |
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
var app = new Vue({ | |
el: '#app', | |
data: function() { | |
return { | |
model: { | |
text: '<button class="btn btn-lg btn-success">Demo Button</button>' | |
}, | |
editor: null | |
} | |
}, | |
created: function() { | |
var scope = this; | |
this.editor = CodeMirror.fromTextArea(document.getElementById('editor'), { | |
lineNumbers: true | |
}); | |
this.editor.on('change', function(cm) { | |
scope.model.text = cm.getValue(); | |
}); | |
} | |
}); |
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
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.15.2/codemirror.js"></script> | |
<script src="https://code.jquery.com/jquery-2.2.4.min.js"></script> | |
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.2/js/bootstrap.min.js"></script> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/1.0.24/vue.js"></script> |
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
body { | |
background: #333; | |
color: #f1f1f1; | |
} | |
.editor-panel { | |
height: 550px; | |
color: #35495e; | |
padding: 0; | |
border: 0; | |
} | |
.card-title { | |
background-color: #35495e; | |
color: #f1f1f1; | |
padding: 2% 4%; | |
} |
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
<link href="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.15.2/codemirror.css" rel="stylesheet" /> | |
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.2/css/bootstrap.min.css" rel="stylesheet" /> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment