1、先看看效果圖,可以自行選擇展示效果
2、這是我在vue3項(xiàng)目中使用的JSON編輯器,首先引入第三方插件
npm install json-editor-vue3
yarn add json-editor-vue3
3、引入到項(xiàng)目中
// 導(dǎo)入模塊
import JsonEditorVue from 'json-editor-vue3'
// 注冊(cè)組件
components: { JsonEditorVue },
4、一般后端返回的是會(huì)將JSON轉(zhuǎn)為String形式,我們傳給后端也是通過(guò)這種形式,就可以通過(guò)后端拿到的數(shù)據(jù)進(jìn)行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\"}}"
// 我們通過(guò)JSON.parse()進(jìn)行轉(zhuǎn)換
let isJson = JSON.parse(configValue) // 這樣我們拿到的就是JSON格式的了,可以渲染出來(lái)的
// 我們傳給后端的數(shù)據(jù)也要將JSON轉(zhuǎn)成字符串,通過(guò)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',
// 注冊(cè)組件
components: {
JsonEditorVue,
},
setup() {
const state = reactive({
currentMode: 'tree'
})
return {
...toRefs(state),
}
},
})
}
</script>
6、參數(shù)文章來(lái)源:http://www.zghlxwxcb.cn/news/detail-419975.html
參數(shù) | 類(lèi)型 | 描述 | 默認(rèn) |
---|---|---|---|
modelValue | Object | 要編輯的json值 | |
options | Object | jsoneditor的options,參考configuration-options | |
currentMode | String | 當(dāng)前編輯模式 | code |
modeList | Array | 可選的編輯模式列表 | [“tree”, “code”, “form”, “text”, “view”] |
language | Array | 語(yǔ)言 | en |
7、事件文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-419975.html
Name | Description |
---|---|
update:modelValue | json 更新 |
change | json 更新 |
textSelectionChange | 參考configuration-options對(duì)應(yīng)參數(shù),參數(shù)有重寫(xiě),第一個(gè)參數(shù)為編輯器的實(shí)例,后續(xù)參數(shù)與官方參數(shù)相同 |
selectionChange | 參考configuration-options對(duì)應(yīng)參數(shù),參數(shù)有重寫(xiě),第一個(gè)參數(shù)為編輯器的實(shí)例,后續(xù)參數(shù)與官方參數(shù)相同 |
focus | 參考configuration-options對(duì)應(yīng)參數(shù),參數(shù)有重寫(xiě),第一個(gè)參數(shù)為編輯器的實(shí)例,后續(xù)參數(shù)與官方參數(shù)相同 |
blur | 參考configuration-options對(duì)應(yīng)參數(shù),參數(shù)有重寫(xiě),第一個(gè)參數(shù)為編輯器的實(shí)例,后續(xù)參數(shù)與官方參數(shù)相同 |
colorPicker | 參考configuration-options對(duì)應(yīng)參數(shù),參數(shù)有重寫(xiě),第一個(gè)參數(shù)為編輯器的實(shí)例,后續(xù)參數(shù)與官方參數(shù)相同 |
到了這里,關(guān)于VUE3使用JSON編輯器的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!