-
Notifications
You must be signed in to change notification settings - Fork 118
/
Copy path+page.svelte
43 lines (36 loc) · 951 Bytes
/
+page.svelte
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<script>
import { JSONEditor } from 'svelte-jsoneditor'
let content = $state({
text: undefined, // can be used to pass a stringified JSON document instead
json: {
array: [1, 2, 3],
boolean: true,
color: '#82b92c',
null: null,
number: 123,
object: { a: 'b', c: 'd' },
string: 'Hello World'
}
})
function handleChange(updatedContent) {
console.log('contents changed:', updatedContent)
content = updatedContent
}
</script>
<svelte:head>
<title>Basic usage (one-way binding) | svelte-jsoneditor</title>
</svelte:head>
<h1>Basic usage (one-way binding)</h1>
<p>
Use JSONEditor with one-way binding: pass read-only property <code>content</code>, and pass an
<code>onChange</code> callback function to receive changes.
</p>
<div class="editor">
<JSONEditor {content} onChange={handleChange} />
</div>
<style>
.editor {
width: 700px;
height: 400px;
}
</style>