VUE3使用JSON編輯器方式
更新時間:2023年10月24日 09:04:23 作者:大吉大利的卦象
這篇文章主要介紹了VUE3使用JSON編輯器方式,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
1、先看看效果圖
可以自行選擇展示效果
2、這是我在vue3項目中使用的JSON編輯器
首先引入第三方插件
npm install json-editor-vue3 yarn add json-editor-vue3
3、引入到項目中
// 導(dǎo)入模塊 import JsonEditorVue from 'json-editor-vue3' // 注冊組件 components: { JsonEditorVue },
4、一般后端返回的是會將JSON轉(zhuǎn)為String形式
我們傳給后端也是通過這種形式
就可以通過后端拿到的數(shù)據(jù)進行JSON與String之間轉(zhuǎn)換
// 后端拿到的數(shù)據(jù) 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()進行轉(zhuǎn)換 let isJson = JSON.parse(configValue) // 這樣我們拿到的就是JSON格式的了,可以渲染出來的 // 我們傳給后端的數(shù)據(jù)也要將JSON轉(zhuǎn)成字符串,通過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> // 導(dǎo)入模塊 import JsonEditorVue from 'json-editor-vue3' export default defineComponent({ name: 'EnterpriseList', // 注冊組件 components: { JsonEditorVue, }, setup() { const state = reactive({ currentMode: 'tree' }) return { ...toRefs(state), } }, }) } </script>
6、參數(shù)
參數(shù) | 類型 | 描述 | 默認 |
---|---|---|---|
modelValue | Object | 要編輯的json值 | |
options | Object | jsoneditor的options,參考configuration-options | |
currentMode | String | 當(dāng)前編輯模式 | code |
modeList | Array | 可選的編輯模式列表 | [“tree”, “code”, “form”, “text”, “view”] |
language | Array | 語言 | en |
7、事件
Name | Description |
---|---|
update:modelValue | json 更新 |
change | json 更新 |
textSelectionChange | 參考configuration-options對應(yīng)參數(shù),參數(shù)有重寫,第一個參數(shù)為編輯器的實例,后續(xù)參數(shù)與官方參數(shù)相同 |
selectionChange | 參考configuration-options對應(yīng)參數(shù),參數(shù)有重寫,第一個參數(shù)為編輯器的實例,后續(xù)參數(shù)與官方參數(shù)相同 |
focus | 參考configuration-options對應(yīng)參數(shù),參數(shù)有重寫,第一個參數(shù)為編輯器的實例,后續(xù)參數(shù)與官方參數(shù)相同 |
blur | 參考configuration-options對應(yīng)參數(shù),參數(shù)有重寫,第一個參數(shù)為編輯器的實例,后續(xù)參數(shù)與官方參數(shù)相同 |
colorPicker | 參考configuration-options對應(yīng)參數(shù),參數(shù)有重寫,第一個參數(shù)為編輯器的實例,后續(xù)參數(shù)與官方參數(shù)相同 |
總結(jié)
以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關(guān)文章
webpack+vuex+axios 跨域請求數(shù)據(jù)的示例代碼
本篇文章主要介紹了webpack+vuex+axios 跨域請求數(shù)據(jù),小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2018-03-03詳解Vue的watch中的immediate與watch是什么意思
這篇文章主要介紹了詳解Vue的watch中的immediate與watch是什么意思,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-12-12解決vue.js出現(xiàn)Vue.js not detected錯誤的問題
這篇文章主要介紹了解決vue.js出現(xiàn)Vue.js not detected錯誤的問題,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2023-10-10