vue项目中使用json编辑器

实现效果:

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

实现过程:

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

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

javascript 复制代码
<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博客

相关推荐
爱笑的源码基地2 小时前
JAVA妇产科专科电子病历系统源码,前端框架:Vue,ElementUI
vue.js·elementui·前端框架·电子病历系统·源代码·java语言开发·产科管理系统源码
香蕉麻花皮3 小时前
vue3 滚动条滑动到元素位置时,元素加载
前端·javascript·vue.js
北城笑笑4 小时前
Echarts中的折线图,多个Y轴集中在左侧(在Vue中使用多个Y轴的折线图)
vue.js·echarts
下一站丶4 小时前
前端引用vue/element/echarts资源等引用方法Blob下载HTML
前端·vue.js·echarts
@Within5 小时前
vite+vue集成cesium
javascript·vue.js·cesium
吱吱喔喔5 小时前
vue3中省市区联动在同一个el-form-item中咋么设置rules验证都不为空的效果
javascript·vue.js·elementui
余十步5 小时前
Vue整合echarts
前端·vue.js·echarts
黑白小怪兽7 小时前
依赖倒置在前端中的典型应用
vue.js·react.js·设计模式
qb7 小时前
vue3响应式原理:reactive
前端·javascript·vue.js
空&白7 小时前
初学vue3与ts:获取组件ref实例
前端·javascript·vue.js