zoukankan      html  css  js  c++  java
  • Vue-json-Editor 封装使用

    Vue-json-Editor

    json可视化编辑器

    安装插件
    npm install vue-json-editor --save

    封装使用方法(父传子)
    ps:父传子,在父组件中通过属性传值,子组件通过prop接收

    1. 新建子组件
    <template>
    <div class="jsonEditor">
        <vue-json-editor
            :style="{'height': height + 'px !important'}"
            v-model="value"
            :mode="'code'"
            @json-change="onJsonChange"
            @json-save="onJsonSave"
            @has-error="onError"
            />
    </div>
    
    </template>
    <script>
    import vueJsonEditor from 'vue-json-editor'
    export default {
        name: "JsonEditor", 
        props:  {
            /* 编辑器的内容 */
            value: {
                type: String,
                default: "",
            },
            height:{
                type: Number,
                default: 260,
            }
        },
        components: { vueJsonEditor },
        data(){
            return {
            }
        },
        methods: {
            onJsonChange (value) {
                // console.log('更改value:', value);
                // 实时保存
                this.onJsonSave(value)
            },
            onJsonSave (value) {
                // console.log('保存value:', value);
                this.resultInfo = value
                this.hasJsonFlag = true
            },
            onError(value) {
                // console.log("json错误了value:", value);
                this.hasJsonFlag = false
            },
            // 检查json
            checkJson(){
                if (this.hasJsonFlag == false){
                // console.log("json验证失败")
                // this.$message.error("json验证失败")
                alert("json验证失败")
                return false
                } else {
                // console.log("json验证成功")
                // this.$message.success("json验证成功")
                alert("json验证成功")
                return true
                }
            },
    
        }
    }
    </script>
    <style >
      /* jsoneditor右上角默认有一个链接,加css去掉了 */
       .jsoneditor-poweredBy{
          display: none;
        }
        .jsoneditor-vue{
            height: 100%;
        }
       
    </style>
    
    1. 在父组件中
      1) 引入组件
      import JsonEditor from "@/components/JsonEditor";
      2) 局部注册组件
      components: { JsonEditor },
      3) 使用组件
    <!-- height 高度  value 展示的数据-->
    <JsonEditor :height="400" :value="form.operParam"></JsonEditor>
  • 相关阅读:
    shell、cmd、dos和脚本语言杂谈(转)
    windows命令之PING DIR DEL CD TASKLIST (转)
    STM32的操作过程,寄存器配置与调试过程(转载)
    关于MCU的烧录,下载与其他接口的比较(一)
    关于Spring Security 3获取用户信息的问题
    Spring security 获取当前用户
    Spring Security3实现,权限动态获取
    Spring Security教程
    spring security 3 自定义认证,授权示例
    SpringSecurity自定义过滤器
  • 原文地址:https://www.cnblogs.com/dzyany/p/14685360.html
Copyright © 2011-2022 走看看