File tree 4 files changed +221
-125
lines changed
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:
77
77
}
78
78
```
79
79
80
- Or scoped:
80
+ or scoped:
81
81
82
82
``` json5
83
83
// package.json
@@ -963,6 +963,48 @@ If you prefer the behavior of svelte-jsoneditor:
963
963
/>
964
964
```
965
965
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
+
966
1008
> See https://github.com/josdejong/svelte-jsoneditor/pull/166 for more details.
967
1009
968
1010
### Boolean properties
Original file line number Diff line number Diff line change @@ -961,6 +961,48 @@ module.exports = {
961
961
/>
962
962
```
963
963
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
+
964
1006
> 详情见 https://github.com/josdejong/svelte-jsoneditor/pull/166
965
1007
966
1008
### 布尔类型属性
Original file line number Diff line number Diff line change 76
76
"vue-demi" : " ^0.14.7"
77
77
},
78
78
"devDependencies" : {
79
- "@antfu/eslint-config" : " ^2.13.2 " ,
79
+ "@antfu/eslint-config" : " ^2.13.3 " ,
80
80
"@commitlint/cli" : " ^19.2.1" ,
81
81
"@commitlint/config-conventional" : " ^19.1.0" ,
82
82
"@types/cross-spawn" : " ^6.0.6" ,
108
108
"rollup-plugin-visualizer" : " ^5.12.0" ,
109
109
"semver" : " ^7.6.0" ,
110
110
"simple-git-hooks" : " ^2.11.1" ,
111
- "typescript" : " ^5.4.4 " ,
111
+ "typescript" : " ^5.4.5 " ,
112
112
"unplugin-auto-import" : " ^0.17.5" ,
113
113
"unplugin-vue-components" : " ^0.26.0" ,
114
114
"vite" : " ^5.2.8" ,
You can’t perform that action at this time.
0 commit comments