当前位置:   article > 正文

vue3.0中前端怎么使用 JSON编译器_vue3 json编辑器

vue3 json编辑器

vue3.0中使用JSON编译器的一般步骤:

1.安装JSON编辑器,引入第三方插件

npm install  json-editor-vue3

 2.在项目中引入该插件

import JsonEditorVue from 'json-editor-vue3'    // 导入模块

components: { JsonEditorVue},     // 注册组件

3.完整代码

<template>

  <div @click.left="changePosition">

    <json-editor-vue

      v-model="isJson"

      class="editor"

      :show-btns="true"

      :expandedOnStart="false"

      :current-mode="currentMode"

      :style="{ height: '500px', overflowX: 'hidden', overflowY: 'auto' }"

    />

  </div>

</template>

<script>

// 导入模块

import JsonEditorVue from 'json-editor-vue3';

export default defineComponent({

  name: 'EnterpriseList',

  //  注册组件

  components: {

    JsonEditorVue,

  },

  setup() {

// 这是拿到的数据

 const    configValue=

“{username:'admin_user',encrypt:'V99HRLkRiWgL4cBgVPOYqF72PKKKF

L7z0Ut8vvDoM6zkf9xwcSI4hcHgj3QmPIWmEg6OjRX5vuToWRMXbZgJUtBp3hwYW

GOW3n4HatHiQCjsarMpxbo1kXt1zsvD/KUjtWTG1B0GfuQcEzmVAMETTIPlooP

srnGMSH4FHhstAA=',}”;

   

// 转化格式  并展示

let isJson = JSON.parse(configValue);

  

//转化成后端所需要的格式

 let isString = JSON.stringify(configValue);

    const state = reactive({

      currentMode: 'code',

    });

    const changePosition = () => {

      console.log(11111);

    };

    return {

      ...toRefs(state),

      changePosition,

      isJson,

    };

  },

});

</script>

<style lang="scss" scope>

.jsoneditor {

  border: none;

}

.jsoneditor-menu {

  display: none;

}

</style>

4.JSON 编译器各参数详情:

参数类型描述默认
modelValueObject要编辑的json值
optionsObjectjsoneditor的options,参考configuration-options
currentModeString当前编辑模式code
modeListArray可选的编辑模式列表[“tree”, “code”, “form”, “text”, “view”]
languageArray语言en

 

NameDescription
update:modelValuejson 更新
changejson 更新
textSelectionChange参考configuration-options对应参数,参数有重写,第一个参数为编辑器的实例,后续参数与官方参数相同
selectionChange参考configuration-options对应参数,参数有重写,第一个参数为编辑器的实例,后续参数与官方参数相同
focus参考configuration-options对应参数,参数有重写,第一个参数为编辑器的实例,后续参数与官方参数相同
blur参考configuration-options对应参数,参数有重写,第一个参数为编辑器的实例,后续参数与官方参数相同
colorPicker参考configuration-options对应参数,参数有重写,第一个参数为编辑器的实例,后续参数与官方参数相同
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/秋刀鱼在做梦/article/detail/1001637
推荐阅读
相关标签
  

闽ICP备14008679号