fix(components): 修复monaco-editor加载json worker报错问题

使用monaco-editor编辑json文件,且开启json验证时,有可能因为加载不到json worker,
monaco.languages对象下会没有json属性,会报undefined错误,进而导致整个编辑器无法使用
This commit is contained in:
madisonlin 2020-08-10 09:56:00 +08:00
parent f0b611b01d
commit 8d9226164b
1 changed files with 2 additions and 2 deletions

View File

@ -16,7 +16,7 @@ function filterUrl(url: string) {
}
(window as any).MonacoEnvironment = {
getWorkerUrl: function(moduleId: string, label: string) {
getWorkerUrl: function (moduleId: string, label: string) {
let url = '/pkg/editor.worker.js';
if (label === 'json') {
@ -202,7 +202,7 @@ export class Editor extends React.Component<EditorProps, any> {
});
// json 默认开启验证。
monaco.languages.json.jsonDefaults.setDiagnosticsOptions({
monaco.languages.json?.jsonDefaults.setDiagnosticsOptions({
enableSchemaRequest: true,
validate: true,
allowComments: true