溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

VUE3怎么使用JSON編輯器

發(fā)布時間:2023-04-28 10:46:50 來源:億速云 閱讀:252 作者:iii 欄目:開發(fā)技術(shù)

這篇文章主要介紹“VUE3怎么使用JSON編輯器”,在日常操作中,相信很多人在VUE3怎么使用JSON編輯器問題上存在疑惑,小編查閱了各式資料,整理出簡單好用的操作方法,希望對大家解答”VUE3怎么使用JSON編輯器”的疑惑有所幫助!接下來,請跟著小編一起來學(xué)習(xí)吧!

1、先看看效果圖,可以自行選擇展示效果

VUE3怎么使用JSON編輯器

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ù)類型描述默認
modelValueObject要編輯的json值
optionsObjectjsoneditor的options,參考configuration-options
currentModeString當前編輯模式code
modeListArray可選的編輯模式列表[“tree”, “code”, “form”, “text”, “view”]
languageArray語言en

7、事件

NameDescription
update:modelValuejson 更新
changejson 更新
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ù)相同

到此,關(guān)于“VUE3怎么使用JSON編輯器”的學(xué)習(xí)就結(jié)束了,希望能夠解決大家的疑惑。理論與實踐的搭配能更好的幫助大家學(xué)習(xí),快去試試吧!若想繼續(xù)學(xué)習(xí)更多相關(guān)知識,請繼續(xù)關(guān)注億速云網(wǎng)站,小編會繼續(xù)努力為大家?guī)砀鄬嵱玫奈恼拢?/p>

向AI問一下細節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI