1.7.2 • Published 3 years ago

vue-json-pretty2 v1.7.2

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

vue-json-pretty

Build Status npm package GitHub license

A vue 2.x component for rendering JSON data as a tree structure.

  • As a JSON Formatter
  • Get item data from JSON

Links

Install

npm install vue-json-pretty --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
      :path="'res'"
      :data="{ key: 'value' }"
      @click="handleClick">
    </vue-json-pretty>
  </div>
</template>

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

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

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

  • If you are using only the normal features (JSON pretty), just focus on the base properties.
  • If you are using higher features (Get data), you can use base and higher attributes.
AttributeLevelDescriptionTypeDefault
datanormaljson dataJSON object-
deepnormaldata depth, data larger than this depth will not be expandednumberInfinity
showLengthnormalwhether to show the length when closedbooleanfalse
showLinenormalwhether to show the linebooleantrue
showDoubleQuotesnormalwhether to show doublequotes on keybooleantrue
highlightMouseoverNodenormalhighlight current node when mouseoverbooleanfalse
v-modelhigherdefines value when the tree can be selectedstring, array-, []
pathhigherroot data pathstringroot
pathCheckedhigherdefines the selected data patharray[]
pathSelectablehigherdefines whether a data path supports selectionFunction(itemPath, itemData)-
selectableTypehigherdefines the selected type, this feature is not supported by defaultenum: -, multiple, single-
showSelectControllerhigherwhether to show the select controller at leftbooleanfalse
selectOnClickNodehigherwhether to change selected value when click nodebooleantrue
highlightSelectedNodehigherhighlight current node when selectedbooleantrue
collapsedOnClickBracketshighercollapsed controlbooleantrue
customValueFormatterhighera function that can return different html or strings to display for values in the data.Function(data, key, parent, defaultFormatted)-

Events

Event NameDescriptionCallback Parameters
clicktriggered when a data item is clicked(path, data)
changetriggered when the selected value changed (only the selectableType not null)(newVal, oldVal)

Major Contributors

npm.io npm.io