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>
相关推荐
盘子素几秒前
前端实现跳转子系统,但限制只能跳转一次
前端·javascript
Anita_Sun几秒前
Lodash 源码解读与原理分析 - Lodash 前世今生:设计原则与演进脉络
前端
爱吃羊的老虎4 分钟前
Streamlit:快速创建应用界面,无需了解 Web 开发
前端·python
满栀5857 分钟前
三级联动下拉框
开发语言·前端·jquery
杨超越luckly14 分钟前
HTML应用指南:利用GET请求获取网易云热歌榜
前端·python·html·数据可视化·网易云热榜
前端_yu小白14 分钟前
React实现Vue的watch和computed
前端·vue.js·react.js·watch·computed·hooks
多看书少吃饭17 分钟前
OnlyOffice 编辑器的实现及使用
前端·vue.js·编辑器
编程之路从0到124 分钟前
JSI入门指南
前端·c++·react native
开始学java25 分钟前
别再写“一锅端”的 useEffect!聊聊 React 副作用的逻辑分离
前端
百度地图汽车版30 分钟前
【智图译站】基于异步时空图卷积网络的不规则交通预测
前端·后端