|
1 | 1 | # vue-json-viewer
|
2 | 2 |
|
3 |
| -Simple json display component, based on vue |
| 3 | +Simple JSON viewer component, for Vue.js 2 |
4 | 4 |
|
5 | 5 | ## Installing:
|
6 | 6 | Using npm:
|
7 | 7 | ```
|
8 | 8 | $ npm install vue-json-viewer
|
9 | 9 | ```
|
10 |
| -Using bower: |
11 |
| - |
12 | 10 |
|
| 11 | +Using yarn: |
13 | 12 | ```
|
14 | 13 | $ yarn add vue-json-viewer
|
15 | 14 | ```
|
16 | 15 |
|
17 | 16 | ## Example:
|
18 | 17 |
|
19 | 18 | ``` html
|
| 19 | +<json-viewer :value="jsonData"></json-viewer> |
| 20 | + |
| 21 | +<hr /> |
| 22 | + |
20 | 23 | <json-viewer
|
21 | 24 | :value="jsonData"
|
22 |
| - :show-copy="true" |
23 |
| - icon-prefix="ion" |
24 |
| - :show-bigger="true" |
25 |
| - :sort-keys="true" /> |
| 25 | + :expand-depth=5 |
| 26 | + copyable |
| 27 | + boxed |
| 28 | + sort></json-viewer> |
26 | 29 | ```
|
27 | 30 |
|
28 | 31 | ``` js
|
29 |
| -export default { |
30 |
| - name: 'Page', |
| 32 | +import Vue from 'vue' |
| 33 | +import JsonViewer from '../lib' |
| 34 | + |
| 35 | +// Import JsonViewer as a Vue.js plugin |
| 36 | +Vue.use(JsonViewer) |
| 37 | + |
| 38 | +new Vue({ |
| 39 | + el: '#app', |
31 | 40 | data() {
|
32 | 41 | return {
|
33 | 42 | jsonData: {
|
34 |
| - name: [ |
35 |
| - {key: 2}, |
36 |
| - {key: 'hello word'}, |
37 |
| - ], |
38 |
| - val: { |
39 |
| - c: () = {}, |
40 |
| - b: 'a', |
41 |
| - a: 'hello word', |
42 |
| - asd2: 1, |
43 |
| - asd: false, |
44 |
| - foo: null, |
45 |
| - bar: undefined |
46 |
| - } |
| 43 | + total: 25, |
| 44 | + limit: 10, |
| 45 | + skip: 0, |
| 46 | + links: { |
| 47 | + previous: undefined, |
| 48 | + next: function () {}, |
| 49 | + }, |
| 50 | + data: [ |
| 51 | + { |
| 52 | + id: '5968fcad629fa84ab65a5247', |
| 53 | + firstname: 'Ada', |
| 54 | + lastname: 'Lovelace', |
| 55 | + awards: null, |
| 56 | + known: [ |
| 57 | + 'mathematics', |
| 58 | + 'computing' |
| 59 | + ], |
| 60 | + position: { |
| 61 | + lat: 44.563836, |
| 62 | + lng: 6.495139 |
| 63 | + }, |
| 64 | + description: `Augusta Ada King, Countess of Lovelace (née Byron; 10 December 1815 – 27 November 1852) was an English mathematician and writer, |
| 65 | + chiefly known for her work on Charles Babbage's proposed mechanical general-purpose computer, |
| 66 | + the Analytical Engine. She was the first to recognise that the machine had applications beyond pure calculation, |
| 67 | + and published the first algorithm intended to be carried out by such a machine. |
| 68 | + As a result, she is sometimes regarded as the first to recognise the full potential of a "computing machine" and the first computer programmer.`, |
| 69 | + bornAt: '1815-12-10T00:00:00.000Z', |
| 70 | + diedAt: '1852-11-27T00:00:00.000Z' |
| 71 | + }, { |
| 72 | + id: '5968fcad629fa84ab65a5246', |
| 73 | + firstname: 'Grace', |
| 74 | + lastname: 'Hopper', |
| 75 | + awards: [ |
| 76 | + 'Defense Distinguished Service Medal', |
| 77 | + 'Legion of Merit', |
| 78 | + 'Meritorious Service Medal', |
| 79 | + 'American Campaign Medal', |
| 80 | + 'World War II Victory Medal', |
| 81 | + 'National Defense Service Medal', |
| 82 | + 'Armed Forces Reserve Medal', |
| 83 | + 'Naval Reserve Medal', |
| 84 | + 'Presidential Medal of Freedom' |
| 85 | + ], |
| 86 | + known: null, |
| 87 | + position: { |
| 88 | + lat: 43.614624, |
| 89 | + lng: 3.879995 |
| 90 | + }, |
| 91 | + description: `Grace Brewster Murray Hopper (née Murray; December 9, 1906 – January 1, 1992) |
| 92 | + was an American computer scientist and United States Navy rear admiral. |
| 93 | + One of the first programmers of the Harvard Mark I computer, |
| 94 | + she was a pioneer of computer programming who invented one of the first compiler related tools. |
| 95 | + She popularized the idea of machine-independent programming languages, which led to the development of COBOL, |
| 96 | + an early high-level programming language still in use today.`, |
| 97 | + bornAt: '1815-12-10T00:00:00.000Z', |
| 98 | + diedAt: '1852-11-27T00:00:00.000Z' |
| 99 | + } |
| 100 | + ] |
47 | 101 | }
|
48 | 102 | }
|
49 | 103 | }
|
50 |
| -} |
| 104 | +}) |
51 | 105 | ```
|
52 | 106 | ## Result:
|
53 |
| - |
| 107 | + |
54 | 108 |
|
55 | 109 |
|
56 | 110 | ## Options:
|
57 | 111 |
|
58 |
| -| Property | Description | |
59 |
| -| ----------- |:------------- | |
60 |
| -| value | json data | |
61 |
| -| show-copy | display the copy button | |
62 |
| -| show-bigger | display the bigger button | |
63 |
| -| icon-prefix | Custom Font icon prefix | |
64 |
| -| sort-keys | Sort items by key names | |
| 112 | +| Property | Description | Default | |
| 113 | +| ----------- |:------------- | ----------- | |
| 114 | +| `value` | JSON data (can be used with `v-model`) | **Required** | |
| 115 | +| `expand-depth` | Display the copy button | `1` | |
| 116 | +| `copyable` | Display the copy button | `false` | |
| 117 | +| `sort` | Sort keys before displaying | `false` | |
| 118 | +| `boxed` | Add a fancy "boxed" style to component | `false` | |
| 119 | +| `theme` | Add a custom CSS class for theming purposes | `jv-light` | |
0 commit comments