Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ The CSS file is included separately and needs to be imported manually. You can e

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

export default {
components: {
Expand All @@ -58,7 +58,7 @@ export default {
import Vue from 'vue'
import VueJsonPretty from 'vue-json-pretty'

Vue.component("vue-json-pretty", VueJsonPretty);
Vue.component("vue-json-pretty", VueJsonPretty)
```

2. In `nuxt.config.js`
Expand Down
170 changes: 120 additions & 50 deletions example/App.vue
Original file line number Diff line number Diff line change
@@ -1,43 +1,69 @@
<template>
<div class="example">
<div class="example-box">
<h2 class="title">EXAMPLE 1</h2>
<h2 class="title">
EXAMPLE 1
</h2>
<div class="block">
<h3>JSON:</h3>
<textarea v-model="val"></textarea>
<textarea v-model="val" />

<h3>Options:</h3>
<div class="options">
<div>
<label>showLength</label>
<input type="checkbox" v-model="showLength">
<input
v-model="showLength"
type="checkbox"
>
</div>
<div>
<label>showLine</label>
<input type="checkbox" v-model="showLine">
<input
v-model="showLine"
type="checkbox"
>
</div>
<div>
<label>showDoubleQuotes</label>
<input type="checkbox" v-model="showDoubleQuotes">
<input
v-model="showDoubleQuotes"
type="checkbox"
>
</div>
<div>
<label>highlightMouseoverNode</label>
<input type="checkbox" v-model="highlightMouseoverNode">
<input
v-model="highlightMouseoverNode"
type="checkbox"
>
</div>
<div>
<label>collapsedOnClickBrackets</label>
<input type="checkbox" v-model="collapsedOnClickBrackets">
<input
v-model="collapsedOnClickBrackets"
type="checkbox"
>
</div>
<div>
<label>use custom formatter</label>
<input type="checkbox" v-model="useCustomLinkFormatter">
<input
v-model="useCustomLinkFormatter"
type="checkbox"
>
</div>
<div>
<label>deep</label>
<select v-model="deep">
<option :value="2">2</option>
<option :value="3">3</option>
<option :value="4">4</option>
<option :value="2">
2
</option>
<option :value="3">
3
</option>
<option :value="4">
4
</option>
</select>
</div>
</div>
Expand All @@ -53,86 +79,125 @@
:highlight-mouseover-node="highlightMouseoverNode"
:collapsed-on-click-brackets="collapsedOnClickBrackets"
:custom-value-formatter="useCustomLinkFormatter ? customLinkFormatter : null"
@click="handleClick">
</vue-json-pretty>
@click="handleClick"
/>
</div>
</div>

<div class="example-box">
<h2 class="title">EXAMPLE 2</h2>
<h2 class="title">
EXAMPLE 2
</h2>
<div class="block">
<h3>JSON:</h3>
<textarea v-model="val"></textarea>
<textarea v-model="val" />

<h3>Options:</h3>
<div class="options">
<div>
<label>selectableType</label>
<select v-model="selectableType">
<option label="-"></option>
<option label="-" />
<option>single</option>
<option>multiple</option>
</select>
</div>
<div>
<label>showSelectController</label>
<input type="checkbox" v-model="showSelectController">
<input
v-model="showSelectController"
type="checkbox"
>
</div>
<div>
<label>selectOnClickNode</label>
<input type="checkbox" v-model="selectOnClickNode">
<input
v-model="selectOnClickNode"
type="checkbox"
>
</div>
<div>
<label>path</label>
<input type="text" v-model="path">
<input
v-model="path"
type="text"
>
</div>
<div>
<label>showLength</label>
<input type="checkbox" v-model="showLength">
<input
v-model="showLength"
type="checkbox"
>
</div>
<div>
<label>showLine</label>
<input type="checkbox" v-model="showLine">
<input
v-model="showLine"
type="checkbox"
>
</div>
<div>
<label>showDoubleQuotes</label>
<input type="checkbox" v-model="showDoubleQuotes">
<input
v-model="showDoubleQuotes"
type="checkbox"
>
</div>
<div>
<label>highlightMouseoverNode</label>
<input type="checkbox" v-model="highlightMouseoverNode">
<input
v-model="highlightMouseoverNode"
type="checkbox"
>
</div>
<div>
<label>highlightSelectedNode</label>
<input type="checkbox" v-model="highlightSelectedNode">
<input
v-model="highlightSelectedNode"
type="checkbox"
>
</div>
<div>
<label>collapsedOnClickBrackets</label>
<input type="checkbox" v-model="collapsedOnClickBrackets">
<input
v-model="collapsedOnClickBrackets"
type="checkbox"
>
</div>
<div>
<label>deep</label>
<select v-model="deep">
<option :value="2">2</option>
<option :value="3">3</option>
<option :value="4">4</option>
<option :value="2">
2
</option>
<option :value="3">
3
</option>
<option :value="4">
4
</option>
</select>
</div>
<div>
<label>use custom formatter</label>
<input type="checkbox" v-model="useCustomLinkFormatter">
<input
v-model="useCustomLinkFormatter"
type="checkbox"
>
</div>
</div>
<h3>v-model:</h3>
<div>{{value}}</div>
<div>{{ value }}</div>
<h3>Current Click:</h3>
<div>path: {{itemPath}}</div>
<div>data: <pre>{{itemData}}</pre></div>
<div>path: {{ itemPath }}</div>
<div>data: <pre>{{ itemData }}</pre></div>
</div>
<div class="block">
<h3>vue-json-pretty:</h3>
<vue-json-pretty
v-if="renderOK"
v-model="value"
:data="json"
:path="path"
:deep="deep"
Expand All @@ -143,25 +208,33 @@
:show-line="showLine"
:select-on-click-node="selectOnClickNode"
:collapsed-on-click-brackets="collapsedOnClickBrackets"
v-model="value"
:path-selectable="((path, data) => typeof data !== 'number')"
:selectable-type="selectableType"
:show-select-controller="showSelectController"
:custom-value-formatter="useCustomLinkFormatter ? customLinkFormatter : null"
@click="handleClick(...arguments, 'complexTree')"
@change="handleChange">
</vue-json-pretty>
@change="handleChange"
/>
</div>
</div>
<a style="position: fixed; right: 0; top: 0;" href="https://github.com/leezng/vue-json-pretty" target="_blank"><img style="position: absolute; top: 0; right: 0; border: 0;" src="https://camo.githubusercontent.com/652c5b9acfaddf3a9c326fa6bde407b87f7be0f4/68747470733a2f2f73332e616d617a6f6e6177732e636f6d2f6769746875622f726962626f6e732f666f726b6d655f72696768745f6f72616e67655f6666373630302e706e67" alt="Fork me on GitHub" data-canonical-src="https://s3.amazonaws.com/github/ribbons/forkme_right_orange_ff7600.png"></a>
<a
style="position: fixed; right: 0; top: 0;"
href="https://github.com/leezng/vue-json-pretty"
target="_blank"
><img
style="position: absolute; top: 0; right: 0; border: 0;"
src="https://camo.githubusercontent.com/652c5b9acfaddf3a9c326fa6bde407b87f7be0f4/68747470733a2f2f73332e616d617a6f6e6177732e636f6d2f6769746875622f726962626f6e732f666f726b6d655f72696768745f6f72616e67655f6666373630302e706e67"
alt="Fork me on GitHub"
data-canonical-src="https://s3.amazonaws.com/github/ribbons/forkme_right_orange_ff7600.png"
></a>
</div>
</template>

<script>
import VueJsonPretty from 'src'

export default {
name: 'app',
name: 'App',
components: {
VueJsonPretty
},
Expand Down Expand Up @@ -202,13 +275,17 @@ export default {
path: 'res',
deep: 3,
itemData: {},
itemPath: ''
itemPath: '',
json: {},
}
},
created () {
this.val = JSON.stringify(this.data)
},
watch: {
val(newVal) {
try {
this.json = JSON.parse(this.val)
} catch (err) {
}
},
selectableType (newVal) {
this.renderOK = false
if (newVal === 'single') {
Expand All @@ -222,15 +299,8 @@ export default {
})
}
},
computed: {
json () {
try {
this.cache = JSON.parse(this.val)
return this.cache
} catch (err) {
return this.cache || this.data
}
}
created () {
this.val = JSON.stringify(this.data)
},
methods: {
handleClick (path, data, treeName = '') {
Expand Down
4 changes: 2 additions & 2 deletions example/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ Vue.config.productionTip = false
/* eslint-disable no-new */
new Vue({
el: '#app',
template: '<App/>',
components: { App }
components: { App },
template: '<App/>'
})
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"build:example": "cross-env EXAMPLE_ENV=true node build/build.js",
"e2e": "node test/e2e/runner.js",
"test": "npm run e2e",
"lint": "eslint --ext .js,.vue src test/e2e/specs"
"lint": "eslint --ext .js,.vue src test/e2e/specs example"
},
"repository": {
"type": "git",
Expand Down