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>
相关推荐
We་ct2 小时前
深度剖析浏览器跨域问题
开发语言·前端·浏览器·跨域·cors·同源·浏览器跨域
weixin_427771613 小时前
前端调试隐藏元素
前端
爱上好庆祝4 小时前
学习js的第五天
前端·css·学习·html·css3·js
C澒4 小时前
IntelliPro 产研协作平台:基于 AI Agent 的低代码智能化配置方案设计与实现
前端·低代码·ai编程
一袋米扛几楼984 小时前
【Git】规范化协作:详解 GitHub 工作流中的 Issue、Branch 与 Pull Request 最佳实践
前端·git·github·issue
网络点点滴4 小时前
前端与后端的区别与联系
前端
EnCi Zheng5 小时前
M5-markconv自定义CSS样式指南 [特殊字符]
前端·css·python
kyriewen5 小时前
你的网页慢,用户不说直接走——前端性能监控教你“读心术”
前端·性能优化·监控
广州华水科技5 小时前
北斗GNSS变形监测在大坝安全监测中的应用与优势分析
前端
前端老石人5 小时前
前端开发中的 URL 完全指南
开发语言·前端·javascript·css·html