您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

VUE3怎么使用JSON编辑器

2024/4/3 8:20:48发布20次查看
1、先看看效果图,可以自行选择展示效果
2、这是我在vue3项目中使用的json编辑器,首先引入第三方插件npm install json-editor-vue3yarn 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、参数参数类型描述默认
modelvalue object 要编辑的json值
options object jsoneditor的options,参考configuration-options
currentmode string 当前编辑模式 code
modelist array 可选的编辑模式列表 [“tree”, “code”, “form”, “text”, “view”]
language array 语言 en
7、事件namedescription
update:modelvalue json 更新
change json 更新
textselectionchange 参考configuration-options对应参数,参数有重写,第一个参数为编辑器的实例,后续参数与官方参数相同
selectionchange 参考configuration-options对应参数,参数有重写,第一个参数为编辑器的实例,后续参数与官方参数相同
focus 参考configuration-options对应参数,参数有重写,第一个参数为编辑器的实例,后续参数与官方参数相同
blur 参考configuration-options对应参数,参数有重写,第一个参数为编辑器的实例,后续参数与官方参数相同
colorpicker 参考configuration-options对应参数,参数有重写,第一个参数为编辑器的实例,后续参数与官方参数相同
以上就是vue3怎么使用json编辑器的详细内容。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product