<a href="https://www.npmjs.com/package/v-object-inspector"> <img alt="Commitizen friendly" src="https://img.shields.io/npm/v/v-object-inspector"> </a> <a href="https://www.npmtrends.com/v-object-inspector"> <img alt="Commitizen friendly" src="http
npm install v-object-inspectorA Vue 3 component for displaying JavaScript objects like Browser DevTools (live demo).
> This repository is a rewrite of vue-object-inspector with Vue 3 and TypeScript.
``bash`
npm install v-object-inspector
Register as a global component:
`ts
import { createApp } from 'vue'
import VObjectInspector from 'v-object-inspector'
import App from './App.vue'
const app = createApp(App)
app.use(VObjectInspector)
app.mount('#app')
`
Or import locally:
`vue
`
| Name | Description | Type | Default | Required |
| ------------------------------------------- | -------------------------------------------------------------- | --------------------- | ------- | -------- |
| data | the JavaScript object to inspect | any | — | true |string
| name | the root node's prefix name | | — | false |number
| expandLevel | the depth level to which the tree should be initially expanded | | 0 | false |string[]
| expandedPaths | the paths in the tree that should be initially expanded | | [] | false |boolean
| showNonEnumerable | whether to show non-enumerable properties | | false | false |boolean \| function
| sortObjectKeys | whether to sort object keys | | false | false |number
| objectMaxProperties | the maximal number of object properties to show in preview | | 5 | false |number
| arrayMaxProperties | the maximal number of array properties to show in preview | | 10 | false |boolean
| darkTheme | whether to use the dark theme or the light theme | | false | false |
- Description: JavaScript object to inspect
- Type: any
- Default: —
- Required: true
- Description: the root node's prefix name
- Type: string
- Default: —
- Required: false
- Description: the depth level to which the tree should be initially expanded
- Type: number0
- Default: expandLevel
- Required: false
- Note: the root node has level 0 and its children have level 1
- Scenarios:
- If want to expand all level, change to a very big number.expandLevel
- If want to collapse all level, change to 0.expandLevel
- If already change expand by hand, change the to a negative number, then change it back in $nextTick.
- Description: the paths in the tree that should be initially expanded
- Type: string[][]
- Default: expandPaths
- Required: false
- Note: a path string in the array follows the syntax like JSONPath['$']
- Examples:
- : expand root node, $ always refers to the root node['$.myKey']
- : expand to myKey node (will also expand all parent nodes)['$.myKey.myArr']
- this is different from react-inspector
- : expand to myArr node (will also expand all parent nodes)['$.a', '$.b']
- : expand first level nodes a and b['$.1']
- : expand by array index['$.*']
- : wildcard, expand all level 2 nodes, equivalent to :expandLevel="2"['$..']
- : wildcard, expand all level 3 nodes, equivalent to :expandLevel="3"
#### expandLevel vs expandPaths
Both expandLevel and expandPaths are reactive.expandLevel
Try avoid using both and expandPaths at the same time.expandLevel
If and expandPaths are used together, when one of them changes, only the changed one will take effect and the other one will be ignored.
- Description: whether to show non-enumerable properties (e.g., __proto__, length, and constructor)boolean
- Type: false
- Default:
- Required: false
- Description: whether to sort object keys
- Type: boolean | functionfalse
- Default: true
- Required: false
- Note: when a compare function is passed, the keys will be sorted as Array.sort() with a compared function
- Examples:
- : sort object keys in alphabetical order (except for arrays)reverseSortFunc
- : sort in reverse alphabetical order (except for arrays)`
js`
const reverseSortFunc = (a, b) => (b > a ? 1 : -1)
- Description: the maximal number of object properties to show in preview
- Type: number5
- Default:
- Required: false
- Description: the maximal number of array properties to show in preview
- Type: number10
- Default:
- Required: false
- Description: whether to use the dark theme or the light theme
- Type: booleanfalse`
- Default:
- Required: false