2023VUE3怎么使用JSON编辑器

 所属分类:web前端开发

 浏览:318次-  评论: 0次-  更新时间:2023-05-15
描述:更多教程资料进入php教程获得。 1、先看看效果图,可以自行选择展示效果2、这是我在vue3项目中使用的JSON编辑器,首先引入第三方插件npm i...
更多教程资料进入php教程获得。

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之间转换

// 后端拿到的数据
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、参数

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

7、事件

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

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

 标签: JSON,Vue3,
积分说明:注册即送10金币,每日签到可获得更多金币,成为VIP会员可免金币下载! 充值积分充值会员更多说明»

讨论这个素材(0)回答他人问题或分享使用心得奖励金币

〒_〒 居然一个评论都没有……

表情  文明上网,理性发言!