Skip to content

Commit 31c01e7

Browse files
committed
docs: provide nuxt 2 / 3 example
1 parent 8705675 commit 31c01e7

File tree

17 files changed

+17348
-67837
lines changed

17 files changed

+17348
-67837
lines changed

README.md

Lines changed: 164 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ English | [简体中文](./docs/README.zh-CN.md)
22

33
# json-editor-vue
44

5-
JSON editor & viewer for Vue 2.6 / 2.7 / 3 and Nuxt 2 / 3, powered by [svelte-jsoneditor](https://github.com/josdejong/svelte-jsoneditor).
5+
JSON editor & viewer for Vue 2.6 / 2.7 / 3 & Nuxt 2 / 3, powered by [svelte-jsoneditor](https://github.com/josdejong/svelte-jsoneditor).
66

77
> svelte-jsoneditor is the successor of [jsoneditor](https://github.com/josdejong/jsoneditor), which ['has become hard to maintain, and the architecture needed a big overhaul'](https://github.com/josdejong/jsoneditor/issues/1223).
88
@@ -19,7 +19,7 @@ JSON editor & viewer for Vue 2.6 / 2.7 / 3 and Nuxt 2 / 3, powered by [svelte-js
1919
- Support Vue 2.6 / 2.7 / 3
2020
- Support SSR (Nuxt 2 / 3)
2121
- Edit mode two-way binding
22-
- Local registration + local configuration, can also be global registration + global configuration (Powered by [vue-global-config](https://github.com/cloydlau/vue-global-config))
22+
- Local registration + local configuration, or global registration + global configuration (Powered by [vue-global-config](https://github.com/cloydlau/vue-global-config))
2323

2424
<br>
2525

@@ -252,6 +252,8 @@ Vue.use(JsonEditorVue, {
252252

253253
### Nuxt 3
254254

255+
#### Local Registration
256+
255257
```vue
256258
<!-- ~/components/JsonEditorVue.client.vue -->
257259
@@ -267,16 +269,62 @@ const value = ref()
267269
```
268270

269271
```vue
270-
<!-- app.vue -->
272+
<template>
273+
<client-only>
274+
<JsonEditorVue v-model="value" />
275+
</client-only>
276+
</template>
271277
278+
<script setup>
279+
const value = ref()
280+
</script>
281+
```
282+
283+
#### Global Registration
284+
285+
```ts
286+
// ~/plugins/JsonEditorVue.client.ts
287+
288+
import JsonEditorVue from 'json-editor-vue'
289+
290+
export default defineNuxtPlugin((nuxtApp) => {
291+
nuxtApp.vueApp.use(JsonEditorVue)
292+
})
293+
```
294+
295+
```vue
272296
<template>
273-
<JsonEditorVue />
297+
<client-only>
298+
<JsonEditorVue v-model="value" />
299+
</client-only>
274300
</template>
301+
302+
<script setup>
303+
const value = ref()
304+
</script>
275305
```
276306

277307
<br>
278308

279-
### Nuxt 2 with Vue 2.7
309+
### Nuxt 2 + Vue 2.7
310+
311+
#### Local Registration
312+
313+
```ts
314+
// nuxt.config.js
315+
316+
export default {
317+
build: {
318+
extend(config) {
319+
config.module.rules.push({
320+
test: /\.mjs$/,
321+
include: /node_modules/,
322+
type: 'javascript/auto',
323+
})
324+
},
325+
},
326+
}
327+
```
280328

281329
```vue
282330
<template>
@@ -286,22 +334,79 @@ const value = ref()
286334
</template>
287335
288336
<script setup>
289-
import Vue, { ref } from 'vue'
337+
import { ref } from 'vue'
338+
339+
const JsonEditorVue = () => process.client
340+
? import('json-editor-vue')
341+
: Promise.resolve({ render: h => h('div') })
290342
343+
const value = ref(undefined)
344+
</script>
345+
```
346+
347+
#### Global Registration
348+
349+
```ts
350+
// nuxt.config.js
351+
352+
export default {
353+
plugins: ['~/plugins/JsonEditorVue.client'],
354+
build: {
355+
extend(config) {
356+
config.module.rules.push({
357+
test: /\.mjs$/,
358+
include: /node_modules/,
359+
type: 'javascript/auto',
360+
})
361+
},
362+
},
363+
}
364+
```
365+
366+
```ts
367+
// ~/plugins/JsonEditorVue.client.js
368+
369+
import Vue from 'vue'
291370
import JsonEditorVue from 'json-editor-vue'
292371

293-
Vue.use(() => process.client
294-
? import('json-editor-vue')
295-
: Promise.resolve({ render: h => h('div') }))
296-
// const JsonEditorVue =
372+
Vue.use(JsonEditorVue)
373+
```
374+
375+
```vue
376+
<template>
377+
<client-only>
378+
<JsonEditorVue v-model="value" />
379+
</client-only>
380+
</template>
381+
382+
<script setup>
383+
import { ref } from 'vue'
297384
298385
const value = ref(undefined)
299386
</script>
300387
```
301388

302389
<br>
303390

304-
### Nuxt 2 with Vue 2.6
391+
### Nuxt 2 + Vue 2.6
392+
393+
#### Local Registration
394+
395+
```ts
396+
// nuxt.config.js
397+
398+
export default {
399+
build: {
400+
extend(config) {
401+
config.module.rules.push({
402+
test: /\.mjs$/,
403+
include: /node_modules/,
404+
type: 'javascript/auto',
405+
})
406+
},
407+
},
408+
}
409+
```
305410

306411
```vue
307412
<template>
@@ -330,6 +435,54 @@ export default {
330435
</script>
331436
```
332437

438+
#### Global Registration
439+
440+
```ts
441+
// nuxt.config.js
442+
443+
export default {
444+
plugins: ['~/plugins/JsonEditorVue.client'],
445+
build: {
446+
extend(config) {
447+
config.module.rules.push({
448+
test: /\.mjs$/,
449+
include: /node_modules/,
450+
type: 'javascript/auto',
451+
})
452+
},
453+
},
454+
}
455+
```
456+
457+
```ts
458+
// ~/plugins/JsonEditorVue.client.js
459+
460+
import Vue from 'vue'
461+
import VueCompositionAPI from '@vue/composition-api'
462+
import JsonEditorVue from 'json-editor-vue'
463+
464+
Vue.use(VueCompositionAPI)
465+
Vue.use(JsonEditorVue)
466+
```
467+
468+
```vue
469+
<template>
470+
<client-only>
471+
<JsonEditorVue v-model="value" />
472+
</client-only>
473+
</template>
474+
475+
<script>
476+
export default {
477+
data() {
478+
return {
479+
value: undefined,
480+
}
481+
},
482+
}
483+
</script>
484+
```
485+
333486
<br>
334487

335488
## Props

demo/nuxt2+vue2.6/nuxt.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export default {
2222

2323
// Plugins to run before rendering page: https://go.nuxtjs.dev/config-plugins
2424
plugins: [
25+
// '~/plugins/JsonEditorVue.client',
2526
],
2627

2728
// Auto import components: https://go.nuxtjs.dev/config-components

0 commit comments

Comments
 (0)