目录

1.前言:

2.使用步骤:

拷贝admin项目中关于这个的,vue文件

npm下载对应的包

接下来可以注册为全局组件

暴露接口,通过:value传输数据给组件,就可以简单使用。

3.注意事项

4.封装成公共组件,可直接使用,基于vue2,运行后按照提示npm下载包


1.前言:

使用的是vue-template-admin中的Json编辑器。目的是展示后端传过来的Json字符串数据。


2.使用步骤:

拷贝admin项目中关于这个的.vue文件

npm下载对应的包

接下来可以注册为全局组件

暴露接口,通过:value传输数据给组件,就可以简单使用。


3.注意事项

1.设置编辑器的样式之类的,需要再引用文件,在node_moudules里面找codemirror文件夹。

2.可以设置的地方很多,可以参考官网,列举一些常用属性:

mode: "text/groovy",    //实现groovy代码高亮
mode: "text/x-java", //实现Java代码高亮
lineNumbers: true,  //显示行号
theme: "dracula", //设置主题
lineWrapping: true, //代码折叠
foldGutter: true,
gutters: ["CodeMirror-linenumbers", "CodeMirror-foldgutter"],
matchBrackets: true,    //括号匹配
//readOnly: true,        //只读

3.除了使用对外暴露的接口外,还可以使用setvalue()方法去赋值


4.封装成公共组件,可直接使用,基于vue2,运行后按照提示npm下载包

新建JsonEditor.vue文件,然后注册为全局组件:

<template>
<!-- 只需要传入数据即可使用:value --><div class="json-editor"><textarea ref="textarea" /></div>
</template>
<style scoped>
@import '../../../node_modules/codemirror/lib/codemirror.css';
@import '../../../node_modules/codemirror/theme/dracula.css';
@import '../../../node_modules/codemirror/addon/lint/lint.css';
</style>
<script>
import CodeMirror from 'codemirror'
import 'codemirror/mode/javascript/javascript'
import 'codemirror/addon/lint/lint'
import 'codemirror/addon/lint/json-lint'
// eslint-disable-next-line import/no-webpack-loader-syntax
require('script-loader!jsonlint')export default {name: 'JsonEditor',/* eslint-disable vue/require-prop-types */props: ['value'],data () {return {jsonEditor: false}},watch: {value (value) {const editorValue = this.jsonEditor.getValue()if (value !== editorValue) {this.jsonEditor.setValue(JSON.stringify(this.value, null, 2))}}},mounted () {this.jsonEditor = CodeMirror.fromTextArea(this.$refs.textarea, {lineNumbers: true,mode: 'application/json',gutters: ['CodeMirror-lint-markers'],theme: 'rubyblue',lint: true,readOnly: true // 只读})this.jsonEditor.setValue(JSON.stringify(this.value, null, 2))this.jsonEditor.on('change', cm => {this.$emit('changed', cm.getValue())this.$emit('input', cm.getValue())})},methods: {getValue () {return this.jsonEditor.getValue()}}
}
</script><style lang="scss" scoped>
.json-editor {text-align-last: left;// width: 100%;// height: 100%;position: relative;::v-deep {.CodeMirror {height: auto;min-height: 300px;}.CodeMirror-scroll {min-height: 300px;}.cm-s-rubyblue span.cm-string {color: #F08047;}}
}
</style>

【codemirror】Json编辑器使用总结相关推荐

  1. # Vue 中 JSON 编辑器使用

    Vue 中 JSON 编辑器使用 文章目录 Vue 中 JSON 编辑器使用 背景描述 vue-json-edit 安装依赖 测试页面 效果图 bin-code-editor 安装依赖 测试页面 效果 ...

  2. 51js 的json编辑器

    无忧JSON编辑器[辅助工具] <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "ht ...

  3. 使用jsonEditor打造一个复杂json编辑器

    最近研究一个web版的json编辑器,在github中搜索,发现了这个利器. https://github.com/jdorn/json-editor 几经研究,终于把该控件的大部分功能研究透彻. 发 ...

  4. antd picker 使用 如何_如何基于jsoneditor二次封装一个可实时预览的json编辑器组件?(react版)...

    前言 做为一名前端开发人员,掌握vue/react/angular等框架已经是必不可少的技能了,我们都知道,vue或react等MVVM框架提倡组件化开发,这样一方面可以提高组件复用性和可扩展性,另一 ...

  5. vue-json-editor json编辑器

    一.概述 现有一个vue项目,需要一个json编辑器,能够格式化json数据,同时也支持编辑功能. vue-json-editor 插件就可以实现这个功能 二.vue-json-editor 使用 安 ...

  6. VUE2使用的JSON编辑器

    1.先看看效果图,可以自行选择展示效果 2.这是我在vue2项目中使用的JSON编辑器,首先引入第三方插件 npm install vue-json-editor --save 3.引入到项目中(最下 ...

  7. 一个能在vue3中运行的JSON编辑器,能展示JSON数据的高亮,打开时有默认数据

    以下是一个可以在Vue 3中运行的JSON编辑器组件.它使用了元素来输入JSON数据,并使用JSON.parse()将输入的JSON数据解析为JavaScript对象.解析成功后,将在编辑器下方展示高 ...

  8. 一个好用的 JSON 编辑器 JsonEditor V1.03.2

    一个好用的 JSON 编辑器 JsonEditor V1.03.2 点击打开 JsonEditor V1.03.2 JSON 因为其它简单易用,被广泛应用的 web 程序上.JSON的良好结构性,使得 ...

  9. 推荐一个好用的JSON编辑器

    推荐一个好用的JSON编辑器 使用说明: http://www.thomasfrank.se/json_editor.html 在线试用: http://www.thomasfrank.se/down ...

  10. JSON编辑器,在线与离线

    JSON编辑器,在这里记录一下. http://jsoneditor.net/ 比较好用 除了在线版,还有AIR版本的离线版 JSONView 有Firefor插件版.还有chrome插件版 ecli ...

最新文章

  1. 5、HTML块级元素及行内元素
  2. Oracle闪回原理-Logminer解读redo(r11笔记第17天)
  3. 低功耗设计——基于UPF进行设计
  4. 用JSLint精炼提升JavaScript代码
  5. python3纵向输出字符串_python3字符串输出常见面试题总结
  6. 2020年,RocketMQ面试题 -面试题驱动RocketMQ学习
  7. 阿里巴巴公司内部资料:交互设计全档案
  8. ES RestClient查询文档
  9. 怎样学习数据结构? 伯克利神课CS61B 总结感悟,学习指南和避坑建议
  10. Windows上免费轻量好用的软件(不定期更新)
  11. 电脑知识与技术杂志电脑知识与技术杂志社电脑知识与技术编辑部2022年第15期目录
  12. HTML translate 属性
  13. 《Towards Conversational Recommendation over Multi-Type Dialogs》解读,融合多个对话类型的对话式推荐
  14. 本地搭建SIP服务器
  15. Android通过来电号码识别姓名。
  16. 2019互联网行业面试资料合集
  17. Win11任务栏消息提醒功能如何开启教学
  18. 如何将背景图改为透明(透明就是我们看到的方格图)
  19. 建行找不到服务器或DNS错误,Win7用浏览器上网总是弹出提示是否停止运行此脚本窗口...
  20. jmeter脚本之AES解密

热门文章

  1. Unity3D脚本编程读书笔记——第2章 Mono脚本核心基础
  2. unity3d脚本控制骨骼旋转
  3. 百家讲坛2001-2016年节目播出表-总目录
  4. nodejs的socket网络编程
  5. 【读书笔记】IOS帝国-Apple Ⅱ/Mac/皮克斯/iPod/iTunes/iPhone/App Store/iPad,苹果教父:史蒂夫·乔布斯传_2020.02.15
  6. 易语言钩子DLL注入源码及源码说明
  7. php编程最快明白第四讲,《PHP编程最快明白》第八讲:php启发和小结_php基
  8. Android刷Root方法,zergRush,Odin3+CWM(ClockworkMod recovery)
  9. 计算机音乐apple,Apple Music苹果音乐电脑版
  10. 取消开机就弹出 msn中文网 操作步骤