首页 > web前端 > Vue.js > 正文

VUE3怎么使用JSON编辑器

PHPz
发布: 2023-05-12 17:34:06
转载
3370人浏览过

1、先看看效果图,可以自行选择展示效果

vue3怎么使用json编辑器

2、这是我在vue3项目中使用的JSON编辑器,首先引入第三方插件

npm install json-editor-vue3

yarn add json-editor-vue3
登录后复制

3、引入到项目中

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

// 注册组件
components: { JsonEditorVue },
登录后复制

4、一般后端返回的是会将JSON转为String形式

我们传给后端也是通过这种形式,就可以通过后端拿到的数据进行JSON与String之间转换

AI图像编辑器
AI图像编辑器

使用文本提示编辑、变换和增强照片

AI图像编辑器 46
查看详情 AI图像编辑器
// 后端拿到的数据
configValue:"{\"isBigTree\":true,\"needContact\":true,\"needProvinceCity\":true,\"needDetailAddress\":true,\"needReservationCheckSms\":false,\"BigTreeReservationConfig\":{\"orderApiUrl\":\"https://api.bigtreedev.com/openplatform/openApi/api/order/create/notification/v001?sign=\",\"reservationApiUrl\":\"https://api.bigtreedev.com/openplatform/openApi/api/service/appointment/create/service/appointment/v001?sign=\",\"cancelApiUrl\":\"https://api.bigtreedev.com/openplatform/openApi/api/order/unsubscribe/notification/v001?sign=\",\"companyNo\":\"C400020\",\"verNo\":\"v001\",\"secretKey\":\"72CDFFD7F63D8662B6E1873FEA14EB24\",\"signSecretId\":\"0BBF774D11C0A053A6C2A2E36E6C6C2E2C55D483\"}}"
// 我们通过JSON.parse()进行转换
let isJson = JSON.parse(configValue) // 这样我们拿到的就是JSON格式的了,可以渲染出来的
// 我们传给后端的数据也要将JSON转成字符串,通过JSON.stringify()
let isString = JSON.stringify(configValue)  // 这样我们拿到的就是String格式的了,直接传给后端
登录后复制

5、例子:

<template>
  <div>
    <json-editor-vue
        v-model="jsonData"
        class="editor"
        :current-mode="currentMode"
    />
  </div>
</template>
 
<script>
  // 导入模块
  import JsonEditorVue from 'json-editor-vue3'
 
  export default defineComponent({
    name: 'EnterpriseList',
    //  注册组件
    components: {
      JsonEditorVue,
    },
    setup() {
      const state = reactive({
        currentMode: 'tree'
      })
      return {
        ...toRefs(state),
      }
    },
  })
  }
</script>
登录后复制

6、参数

参数 类型 描述 默认
modelValue Object 要编辑的json值
options Object jsoneditor的options,参考configuration-options
currentMode String 当前编辑模式 code
modeList Array 可选的编辑模式列表 [“tree”, “code”, “form”, “text”, “view”]
language Array 语言 en

7、事件

Name Description
update:modelValue json 更新
change json 更新
textSelectionChange 参考configuration-options对应参数,参数有重写,第一个参数为编辑器的实例,后续参数与官方参数相同
selectionChange 参考configuration-options对应参数,参数有重写,第一个参数为编辑器的实例,后续参数与官方参数相同
focus 参考configuration-options对应参数,参数有重写,第一个参数为编辑器的实例,后续参数与官方参数相同
blur 参考configuration-options对应参数,参数有重写,第一个参数为编辑器的实例,后续参数与官方参数相同
colorPicker 参考configuration-options对应参数,参数有重写,第一个参数为编辑器的实例,后续参数与官方参数相同

以上就是VUE3怎么使用JSON编辑器的详细内容,更多请关注php中文网其它相关文章!

相关标签:
最佳 Windows 性能的顶级免费优化软件
最佳 Windows 性能的顶级免费优化软件

每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。

下载
来源:亿速云网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号