「Vue JSON Tree View」でTree形式でJSONを表示する

「Vue JSON Tree View」でTree形式でJSONを表示する

Vue JSON Tree Viewとは

「Vue JSON Tree View」でTree形式でJSONを表示する

 

Vue JSON Tree Viewは、Tree形式JSONを表示するライブラリです。

 

インストール

以下のnpmCDNを使ってインストールします。

npm

npm install --save vue-json-tree-view

CDN

<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/vue-json-tree-view.min.js"></script>

 

gitリポジトリは以下から取得できます。

https://github.com/michaelfitzhavey/vue-json-tree-view

導入手順

Tree形式JSONを表示します。

1. ライブラリの取り込み

(1)webpack等の場合 ※モジュール版は未検証です。

import TreeView from "vue-json-tree-view"
Vue.use(TreeView)

(2)WEBページの場合

Vue.use(TreeView);

2.メソッドを設定

new Vue({
  el: '#app',
  data: {
    jsonSource: [
      {id:1, text:'text1'},
      {id:2, text:'text2'},
      {id:3, text:'text3'},
      {id:4, text:'text4'},
      {id:5, list:[
        {id:1, text:'text1'},
        {id:2, text:'text2'},
        {id:3, text:'text3'},
        {id:4, list:[
          {id:1, text:'text1'},
          {id:2, text:'text2'},
          {id:3, text:'text3'},
        ]},
      ]}
    ]
  }
})

3. <tree-view>テンプレートを準備

<div id="app">
  <tree-view :data="jsonSource" :options="{maxDepth: 3}"></tree-view>
</div>

 

サンプル

>>専用ページで確認する

 

さいごに

Tree形式JSONを表示するライブラリでした。

WEBサイトとかに使う用途は無さそうですが、アプリなどのデバッグには使えそうな気がします。

今日はこの辺でー

 

  • この記事を書いた人

カバノキ

印刷会社のWEB部隊に所属してます。 WEB制作に携わってから、もう時期10年になります。 普段の業務では、PHPをメインにサーバーサイドの言語を扱っています。 最近のお気に入りはJavascriptです。 Vue.jsを狂喜乱舞しながら、社内に布教中です。

-vue.js
-, ,