标签:component 文件 文本 ons The efault var dem enum
javascript bower i codemirror
html <link rel="stylesheet" type="text/css" href="bower_components/codemirror/lib/codemirror.css">
html <script type="text/javascript" src="bower_components/codemirror/lib/codemirror.js"></script> <script type="text/javascript" src="bower_components/codemirror/mode/javascript/javascript.js"></script> <script type="text/javascript" src="bower_components/codemirror/mode/xml/xml.js"></script> <script type="text/javascript" src="bower_components/codemirror/mode/htmlmixed/htmlmixed.js"></script> <script type="text/javascript" src="bower_components/codemirror/mode/css/css.js"></script>
html <div class="container"> <textarea class="marpad " tyle="width:70%;height:300px;" id="editor" > <!-- 放入编辑对应的文本 --> </textarea> </div>
javascript // mode: "text/javascript", // mode: "text/css" window.onload = function(){ var myCodeMirror = CodeMirror.fromTextArea(document.getElementById("editor"), { lineNumbers: true, mode: "text/html" }); }
javascript npm i -S vue-codemirror
javascript // codemirror 引入和使用 import VueCodemirror from ‘vue-codemirror‘ import ‘codemirror/lib/codemirror.css‘ Vue.use(VueCodemirror)
.vue文件中使用
template部分,使用双向绑定的写法
//v-model="infor.codeCss" 双向绑定的数据源
//:options="cssOptions" codemirror的配置项
<codemirror v-model="infor.codeCss" :options="cssOptions"></codemirror>
script部分
//引入xml,html,css,js对应的js解析文件
import ‘codemirror/mode/javascript/javascript.js‘
import ‘codemirror/mode/css/css.js‘
import ‘codemirror/mode/xml/xml.js‘
import ‘codemirror/mode/htmlmixed/htmlmixed.js‘
// 引入主题样式文件
import ‘codemirror/theme/monokai.css‘
//Vue实例中设置配置项
data(){
return {
infor:{
codeCss:‘‘
},
cssOptions: {
tabSize: 4,
mode: ‘text/css‘,
theme: ‘monokai‘,
lineNumbers: true,
line: true,
}
}
}
标签:component 文件 文本 ons The efault var dem enum
原文地址:https://www.cnblogs.com/nordon-wang/p/9141426.html