使用bin-code-editor格式化JSON字符串并在页面中展示

 

 把上面这种格式的数据像这个样子展示出来

在package.json中加入  "bin-code-editor": "^0.9.0",然后npm i 下载依赖包或者直接npm i bin-code-editor

在main.js中写入

import Vue from 'vue';
import CodeEditor from 'bin-code-editor';
import 'bin-code-editor/lib/style/index.css';
import App from './App.vue';

Vue.use(CodeEditor);

new Vue({
  el: '#app',
  render: h => h(App)
});

用法:在dialog弹窗中放置这个组件

  <div v-else class="syncParamContent">
        <!-- <pre>{{ JSON.parse(syncParamValue) }}</pre> -->
        <b-code-editor
          class="titleJson"
          v-model="syncParamValue" // 定义绑定的数据
          readonly
          :auto-format="true"
          :smart-indent="true"
          theme="material" // 支持多种主题色
          :indent-unit="4"
          :lint="false"
          height="600px"
          ref="editor"
        ></b-code-editor>
      </div>

 调整对应样式代码

.syncParamContent {
  margin-top: -28px;
  width: 100%;
  height: 600px;
  border-radius: 5px;
  padding: 5px;
  box-sizing: border-box;
  overflow-y: hidden;
  background: #f7f8fa;
}
.titleJson::v-deep .CodeMirror {
  height: 600px;
  background: #1d2129;
  font-family: Consolas, "Courier New", monospace;
  font-weight: normal;
  font-size: 13px;
  font-feature-settings: "liga" 0, "calt" 0;
  line-height: 24px;
  letter-spacing: 0px;
  border-radius: 10px;
}
::v-deep .CodeMirror-vscrollbar {
  width: 0px;
  height: 100%;
}
::v-deep .CodeMirror-vscrollbar {
  background: rgba(240, 207, 207, 1);
  border-radius: 10px;
}

html::-webkit-scrollbar,
body::-webkit-scrollbar,
.syncParamContent::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

html::-webkit-scrollbar-thumb,
body::-webkit-scrollbar-thumb,
.syncParamContent::-webkit-scrollbar-thumb {
  background: #e5e6eb;
  border-radius: 5px;
}

  • 14
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
bin-code-editor是一个代码编辑器的依赖库。在软件开发,代码编辑器是一种工具,用于编辑、查看和修改代码文件。bin-code-editor在实现代码编辑器的功能时,提供了一些必要的功能和组件。 首先,bin-code-editor具有代码高亮的功能。它可以根据代码的语法规则,对不同的代码部分进行不同的颜色显示,使得代码更加易读和易于理解。代码高亮功能对于开发者来说非常重要,可以帮助他们快速定位和理解代码的关键部分。 其次,bin-code-editor提供了代码补全的功能。在编写代码的过程,有时会遇到需要输入长的函数名或者变量名的情况。代码补全功能可以根据已有的代码内容,给出可能的补全选项,帮助开发者节省时间和减少输入错误。 另外,bin-code-editor支持多种编程语言。不同的编程语言有不同的语法规则和关键字,因此对于不同的语言,代码编辑器需要有相应的支持和适配。bin-code-editor提供了对多种流行编程语言的支持,包括但不限于Java、Python、JavaScript等。 此外,bin-code-editor还支持代码调试功能。在开发过程,经常需要对代码进行调试和验证。代码调试功能可以帮助开发者逐行执行代码,并在运行过程查看变量的值和程序流程。bin-code-editor提供了对断点的设置和调试过程的控制,方便开发者进行代码调试工作。 总之,bin-code-editor是一个功能强大的代码编辑器依赖库,提供了常用的代码编辑和调试功能,帮助开发者提高编码效率和代码质量。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值