场景
若依前后端分离版手把手教你本地搭建环境并运行项目:
若依前后端分离版手把手教你本地搭建环境并运行项目_霸道流氓气质的博客-CSDN博客_若依前后端分离
在上面的基础上,怎样实现代码在线编辑功能。
注:
博客:
霸道流氓气质的博客_CSDN博客-C#,架构之路,SpringBoot领域博主
关注公众号
霸道的程序猿
获取编程相关电子书、教程推送与免费下载。
实现
1、插件地址
GitHub – surmon-china/vue-codemirror: ⌨️ @codemirror component for @vuejs
在线演示地址
2、安装插件
npm install vue-codemirror --save
3、全局挂载插件方式或者局部页面加载方式
全局挂载
import Vue from 'vue'
import VueCodemirror from 'vue-codemirror'
// import base style
import 'codemirror/lib/codemirror.css'
// import more codemirror resource...
// you can set default global options and events when Vue.use
Vue.use(VueCodemirror, /* {
options: { theme: 'base16-dark', ... },
events: ['scroll', ...]
} */)
局部页面引用
import { codemirror } from 'vue-codemirror'
// import base style
import 'codemirror/lib/codemirror.css'
// import more codemirror resource...
export default {
components: {
codemirror
}
}
4、新建Vue页面代码修改如下
<template>
<!-- Two-way Data-Binding -->
<!-- <codemirror v-model="code" :options="cmOptions" /> -->
<!-- Or manually control the data synchronization -->
<codemirror
ref="cmEditor"
:value="code"
:options="cmOptions"
@ready="onCmReady"
@focus="onCmFocus"
@input="onCmCodeChange"
/>
</template>
<script>
import { codemirror } from 'vue-codemirror'
// import base style
import 'codemirror/lib/codemirror.css'
// import language js
import 'codemirror/mode/javascript/javascript.js'
// import theme style
import 'codemirror/theme/base16-dark.css'
// import more 'codemirror/some-resource...'
export default {
name: "codemirrorDemo",
components: {
codemirror
},
data () {
return {
code: 'const a = 10',
cmOptions: {
tabSize: 4,
mode: 'text/javascript',
theme: 'base16-dark',
lineNumbers: true,
line: true,
// more CodeMirror options...
}
}
},
methods: {
onCmReady(cm) {
console.log('the editor is readied!', cm)
},
onCmFocus(cm) {
console.log('the editor is focused!', cm)
},
onCmCodeChange(newCode) {
console.log('this is new code', newCode)
this.code = newCode
}
},
computed: {
codemirror() {
return this.$refs.cmEditor.codemirror
}
},
mounted() {
console.log('the current CodeMirror instance object:', this.codemirror)
// you can use this.codemirror to do something...
}
}
</script>
5、其他设置参考官方说明
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
文章由极客之音整理,本文链接:https://www.bmabk.com/index.php/post/135971.html