File tree Expand file tree Collapse file tree 4 files changed +221
-125
lines changed Expand file tree Collapse file tree 4 files changed +221
-125
lines changed Original file line number Diff line number Diff line change @@ -77,7 +77,7 @@ If you want to specify dependency versions:
7777}
7878```
7979
80- Or scoped:
80+ or scoped:
8181
8282``` json5
8383// package.json
@@ -963,6 +963,48 @@ If you prefer the behavior of svelte-jsoneditor:
963963/>
964964```
965965
966+ If you want to ensure you always get parsed JSON in text mode:
967+
968+ > [ !Caution]
969+ >
970+ > Not performant for large JSON documents.
971+
972+ ``` ts
973+ createApp (App )
974+ .use (JsonEditorVue , {
975+ mode: ' text' ,
976+ mainMenuBar: false ,
977+ onChange(updatedContent ) {
978+ if (updatedContent .text ) {
979+ try {
980+ updatedContent .json = JSON .parse (updatedContent .text )
981+ }
982+ catch {}
983+ updatedContent .text = undefined
984+ }
985+ },
986+ })
987+ .mount (' #app' )
988+ ```
989+
990+ or without ` try...catch ` :
991+
992+ ``` html
993+ <JsonEditorVue
994+ ref =" jsonEditorVueRef"
995+ mode =" text"
996+ :main-menu-bar =" false"
997+ :on-change =" (updatedContent) => {
998+ if (updatedContent.text) {
999+ if (!jsonEditorVueRef.jsonEditor.validate()) {
1000+ updatedContent.json = JSON.parse(updatedContent.text)
1001+ }
1002+ updatedContent.text = undefined
1003+ }
1004+ }"
1005+ />
1006+ ```
1007+
9661008> See https://github.com/josdejong/svelte-jsoneditor/pull/166 for more details.
9671009
9681010### Boolean properties
Original file line number Diff line number Diff line change @@ -961,6 +961,48 @@ module.exports = {
961961/>
962962```
963963
964+ 如果你想确保在 text 模式中总是得到 “parsed JSON”:
965+
966+ > [ !Caution]
967+ >
968+ > 对于大型 JSON 文档性能不佳
969+
970+ ``` ts
971+ createApp (App )
972+ .use (JsonEditorVue , {
973+ mode: ' text' ,
974+ mainMenuBar: false ,
975+ onChange(updatedContent ) {
976+ if (updatedContent .text ) {
977+ try {
978+ updatedContent .json = JSON .parse (updatedContent .text )
979+ }
980+ catch {}
981+ updatedContent .text = undefined
982+ }
983+ },
984+ })
985+ .mount (' #app' )
986+ ```
987+
988+ 或不使用 ` try...catch ` :
989+
990+ ``` html
991+ <JsonEditorVue
992+ ref =" jsonEditorVueRef"
993+ mode =" text"
994+ :main-menu-bar =" false"
995+ :on-change =" (updatedContent) => {
996+ if (updatedContent.text) {
997+ if (!jsonEditorVueRef.jsonEditor.validate()) {
998+ updatedContent.json = JSON.parse(updatedContent.text)
999+ }
1000+ updatedContent.text = undefined
1001+ }
1002+ }"
1003+ />
1004+ ```
1005+
9641006> 详情见 https://github.com/josdejong/svelte-jsoneditor/pull/166
9651007
9661008### 布尔类型属性
Original file line number Diff line number Diff line change 7676 "vue-demi" : " ^0.14.7"
7777 },
7878 "devDependencies" : {
79- "@antfu/eslint-config" : " ^2.13.2 " ,
79+ "@antfu/eslint-config" : " ^2.13.3 " ,
8080 "@commitlint/cli" : " ^19.2.1" ,
8181 "@commitlint/config-conventional" : " ^19.1.0" ,
8282 "@types/cross-spawn" : " ^6.0.6" ,
108108 "rollup-plugin-visualizer" : " ^5.12.0" ,
109109 "semver" : " ^7.6.0" ,
110110 "simple-git-hooks" : " ^2.11.1" ,
111- "typescript" : " ^5.4.4 " ,
111+ "typescript" : " ^5.4.5 " ,
112112 "unplugin-auto-import" : " ^0.17.5" ,
113113 "unplugin-vue-components" : " ^0.26.0" ,
114114 "vite" : " ^5.2.8" ,
You can’t perform that action at this time.
0 commit comments