json数据转换工具-js

json数据转换

js插件:
https://github.com/josdejong/jsoneditor
在这里插入图片描述
在vue中使用:
1.下载

npm install jsoneditor

auditLog.vue:
在vue里面写一个id为"jsoneditor"的div,组件就展示在这个div里面

<div id="jsoneditor" style="width: 50%; height: 500px"></div>

auditLog.js:
detailDialog 是我写在弹窗里面的,visible是打开弹窗,可忽略
首先引入组件的js以及css
通过document.getElementById找到名为jsoneditor的div
new 一个 JSONEditor对象
initialJson里面放数据
最后再editor.set出去

//详情弹窗
let visible = ref(false)
const detailDialog = () => {
    visible.value = true
    setTimeout(() => {
        let JSONEditor = require("jsoneditor/dist/jsoneditor.js")
        require("jsoneditor/dist/jsoneditor.min.css")
        console.log(JSONEditor)
        const container = document.getElementById("jsoneditor")
        const options = {}
        const editor = new JSONEditor(container, options)

        // set json
        const initialJson = {
            "Array": [1, 2, 3],
            "Boolean": true,
            "Null": null,
            "Number": 123,
            "Object": {
                "a": "b",
                "c": "d"
            },
            "String": "Hello World"
        }
        editor.set(initialJson)

        // get json
        const updatedJson = editor.get()
    }, 300)
}

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值