Home

Awesome

<p align="center"> <a href="https://github.com/leezng/vue-json-pretty"> <img width="200" src="./static/logo.svg"> </a> </p> <h1 align="center"> <a href="https://github.com/leezng/vue-json-pretty" target="_blank">Vue Json Pretty</a> </h1> <div align="center"> <p>A Vue component for rendering JSON data as a tree structure.</p> <p>Now it supports Vue3 at least. If you still use Vue2, see <a href="https://github.com/leezng/vue-json-pretty/tree/1.x">1.x</a>.</p>

Build Status npm package GitHub license Sizes NPM downloads Issues

</div>

English | 简体中文

Features

Environment Support

<img src="https://raw.githubusercontent.com/alrra/browser-logos/master/src/edge/edge_48x48.png" alt="IE / Edge" width="24px" height="24px" /></br>IE / Edge<img src="https://raw.githubusercontent.com/alrra/browser-logos/master/src/firefox/firefox_48x48.png" alt="Firefox" width="24px" height="24px" /></br>Firefox<img src="https://raw.githubusercontent.com/alrra/browser-logos/master/src/chrome/chrome_48x48.png" alt="Chrome" width="24px" height="24px" /></br>Chrome<img src="https://raw.githubusercontent.com/alrra/browser-logos/master/src/safari/safari_48x48.png" alt="Safari" width="24px" height="24px" /></br>Safari<img src="https://raw.githubusercontent.com/alrra/browser-logos/master/src/electron/electron_48x48.png" alt="Electron" width="24px" height="24px" /></br>Electron
IE11, Edgelast 10 versionslast 10 versionslast 10 versionslast 2 versions

Using NPM or Yarn

$ npm install vue-json-pretty --save
$ yarn add vue-json-pretty

Use Vue2

$ npm install vue-json-pretty@v1-latest --save

Usage

The CSS file is included separately and needs to be imported manually. You can either import CSS globally in your app (if supported by your framework) or directly from the component.

<template>
  <div>
    <vue-json-pretty :data="{ key: 'value' }" />
  </div>
</template>

<script>
import VueJsonPretty from 'vue-json-pretty';
import 'vue-json-pretty/lib/styles.css';

export default {
  components: {
    VueJsonPretty,
  },
};
</script>

Use Nuxt.js

  1. In plugins/vue-json-pretty.js
import Vue from 'vue'
import VueJsonPretty from 'vue-json-pretty'

Vue.component("vue-json-pretty", VueJsonPretty)
  1. In nuxt.config.js
css: [
  'vue-json-pretty/lib/styles.css'
],
plugins: [
  '@/plugins/vue-json-pretty'
],

Props

PropertyDescriptionTypeDefault
data(v-model)JSON data, support v-model when use editableJSON object-
collapsedNodeLengthObjects or arrays which length is greater than this threshold will be collapsednumber-
deepPaths greater than this depth will be collapsednumber-
showLengthShow the length when collapsedbooleanfalse
showLineShow the linebooleantrue
showLineNumberShow the line numberbooleanfalse
showIconShow the iconbooleanfalse
showDoubleQuotesShow doublequotes on keybooleantrue
virtualUse virtual scrollbooleanfalse
heightThe height of list when using virtualnumber400
itemHeightThe height of node when using virtualnumber20
selectedValue(v-model)Selected data pathstring, array-
rootPathRoot data pathstringroot
nodeSelectableDefines whether a node supports selection(node) => boolean-
selectableTypeSupport path select, default nonemultiple | single-
showSelectControllerShow the select controllerbooleanfalse
selectOnClickNodeTrigger select when click nodebooleantrue
highlightSelectedNodeSupport highlighting selected nodesbooleantrue
collapsedOnClickBracketsSupport click brackets to collapsebooleantrue
renderNodeKeyrender node key, or use slot #renderNodeKey({ node, defaultKey }) => vNode-
renderNodeValuerender node value, or use slot #renderNodeValue({ node, defaultValue }) => vNode-
editableSupport editablebooleanfalse
editableTriggerTriggerclick | dblclickclick
themeSets the theme of the component. Options are 'light' or 'dark', with dark mode enhancing visibility on dark backgrounds'light' | 'dark'light

Events

Event NameDescriptionParameters
nodeClicktriggers when click node(node: NodeData)
bracketsClicktriggers when click brackets(collapsed: boolean, node: NodeData)
iconClicktriggers when click icon(collapsed: boolean, node: NodeData)
selectedChangetriggers when the selected value changed(newVal, oldVal)

Slots

Slot NameDescriptionParameters
renderNodeKeyrender node key{ node, defaultKey }
renderNodeValuerender node value{ node, defaultValue }

Contributors

<a href="https://github.com/leezng/vue-json-pretty/graphs/contributors"> <img src="https://contrib.rocks/image?repo=leezng/vue-json-pretty" /> </a>