vue-json-editor

复制代码
版本:"vue-json-editor": "^1.4.3"

(1)下载依赖,npm install vue-json-editoryarn add vue-json-editor

(2)使用

复制代码
<div class="code-json-editor">
    <vue-json-editor
        v-model="jsonEditorData"
        :showBtns="false" // 不显示保存按钮
        :mode="'code'" // 默认选择code格式
        lang="zh" // 中文
        :expandedOnStart="true" // 默认展开数据
        @json-change="jsonEditorDataChange" // 当输入的数据符合json对象格式时
        @has-error="jsonEditorDataHasError"/> // 当输入的数据不符合json对象格式时
    </div>
    <div v-if="showErrorTips">格式错误,请输入json格式</div>
</div>

<script>
import VueJsonEditor from 'vue-json-editor'
export default {
    components: {
        VueJsonEditor
    },
    data () {
        return {
          showErrorTips: false,
          jsonEditorData: {}
        }
    },
    methods: {
        jsonEditorDataChange (json) {
            this.jsonEditorData = json
            this.showErrorTips = false
        },
        jsonEditorDataHasError (error) {
            // 当清空输入的数据时
            if (error.message && error.message.includes("Expecting 'STRING', 'NUMBER', 'NULL', 'TRUE', 'FALSE', '{', '[', got 'EOF'")) {
                this.jsonEditorData= {}
                this.showErrorTips = false
            } else {
                this.showErrorTips = true
            }
        }
    }
}
</script>

// 隐藏 右上角链接
<style scoped="scoped">
    .code-json-editor >>> .jsoneditor-poweredBy {
        display: none !important;
    }
</style>
相关推荐
几何心凉1 天前
openGauss:多核时代企业级数据库的性能与高可用新标杆
前端·数据库·数据库开发
AiXed1 天前
PC微信协议之AES-192-GCM算法
前端·数据库·python
AllData公司负责人1 天前
实时开发平台(Streampark)--Flink SQL功能演示
大数据·前端·架构·flink·开源
小满zs1 天前
Next.js第五章(动态路由)
前端
清沫1 天前
VSCode debugger 调试指南
前端·javascript·visual studio code
一颗宁檬不酸1 天前
页面布局练习
前端·html·页面布局
金木讲编程1 天前
Claude、Agent与Copilot协作生成Angular应用
前端·ai编程
振华OPPO1 天前
Vue:“onMounted“ is defined but never used no-unused-vars
前端·javascript·css·vue.js·前端框架
欧雷殿1 天前
在富阳银湖成立地域化的软件研发团队
前端·程序员·创业
李慕婉学姐1 天前
【开题答辩过程】以《Javaweb的火花流浪动物救助系统设计与实现》为例,不会开题答辩的可以进来看看
vue.js·spring boot·mysql