vue项目中使用json编辑器

 实现效果:

借助插件json-editor-vue3实现效果如图一,如果嫌丑可以通过类名改一下样式如图二。

 

实现过程:

安装插件:npm install json-editor-vue3

文档链接:GitCode - 开发者的代码家园

<script setup name="dataPreView">
import JsonEditorVue from 'json-editor-vue3';
// 数据是否在加载中
let dataLoading = $ref(false);
let dataSql = $ref('');
// json配置
const couldView = $ref(['tree', 'code', 'form', 'view', 'text']);
// json修改
const updateModelValue = (val) => {
    console.log(val, '修改了值');
};
</script>

<template>
    <div v-loading="dataLoading">
        <JsonEditorVue
            v-model="dataSql"
            class="myJsonEditor"
            style="height: 580px"
            :modeList="couldView"
            currentMode="code"
            @update:model-value="updateModelValue"
        ></JsonEditorVue>
    </div>
</template>
<style lang="less">
.myJsonEditor {
    .jsoneditor-menu > .jsoneditor-modes > button,
    .jsoneditor-menu > button {
        background-color: #6284ff;
    }
    .jsoneditor-menu > .jsoneditor-modes > button:hover,
    .jsoneditor-menu > button:hover {
        background-color: #6284ff;
    }
    .jsoneditor-menu > .jsoneditor-modes > button:focus,
    .jsoneditor-menu > button:focus {
        background-color: #6284ff;
    }
    .jsoneditor-menu {
        background-color: #ecf0fd;
        border-bottom: none;
    }
    .jsoneditor {
        border: 1px solid #dae3ff;
    }
    .ace-jsoneditor .ace_gutter {
        background-color: #f7f7f7;
    }
    .jsoneditor-statusbar {
        background-color: #f7f7f7;
        border-top: 1px solid #dae3ff;
    }
    .full-screen {
        background-color: #6284ff;
    }
    .jsoneditor-poweredBy {
        color: #6284ff;
    }
    .ace_gutter-cell.ace_error,
    .ace_icon.ace_error,
    .ace_icon.ace_error_fold {
        background-image: url(../imgs/task/inputClose.png);
        background-size: 14px 14px;
    }
    .ace-jsoneditor .ace_marker-layer .ace_active-line {
        background: #fafafa;
    }
    .jsoneditor-statusbar {
        display: none;
    }
}
</style>

参考文档:

json-editor-vue3 (Json字段编辑器 )-CSDN博客 

【前端】Vue项目中 JSON 编辑器的使用_vue json 编辑器-CSDN博客

 

  • 4
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值