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་ct30 分钟前
React 性能优化精讲
前端·javascript·react.js·性能优化·前端框架·html·浏览器
云动课堂40 分钟前
【运维实战】Nginx 高性能Web服务 · 一键自动化部署方案 (适配银河麒麟 V10 / openEuler / CentOS 7/8)
运维·前端·nginx
大前端helloworld2 小时前
AI全自动实现Flutter蓝牙自动连接
前端
GISer_Jing2 小时前
从入门到落地:前端开发者的AI Agent全栈学习路线
前端·人工智能·ai编程
计算机安禾2 小时前
【Linux从入门到精通】第47篇:SystemTap与eBPF——Linux内核观测的显微镜
java·linux·前端
技术钱3 小时前
OutputParser输出解析器
linux·服务器·前端·python
可达鸭小栈4 小时前
易语言实现CSS像素文字生成器:无需字体文件渲染汉字
前端·css
fox_lht4 小时前
DBeaver的LightGrid 类所有函数详细分析
前端
钛态4 小时前
前端TypeScript高级技巧:让你的代码更安全
前端·vue·react·web
光影少年4 小时前
前端在页面渲染优化和组件优化经验?
前端·vue.js·react.js·前端框架