javascript - 如何将 JSON 与 react-ace 一起使用?
问题描述
我使用react-ace并尝试使用 java 语法的自述文件示例。效果很好。但我似乎无法将其设置为 JSON。
Java 工作
import AceEditor from "react-ace";
import "ace-builds/src-noconflict/mode-java";
import "ace-builds/src-noconflict/theme-github";
<AceEditor
mode="java"
theme="github"
name="UNIQUE_ID_OF_DIV"
editorProps={{ $blockScrolling: true }}
/>
JSON 不起作用?
import AceEditor from "react-ace";
import "ace-builds/src-noconflict/mode-json";
import "ace-builds/src-noconflict/theme-github";
<AceEditor
mode="json"
theme="github"
name="UNIQUE_ID_OF_DIV"
editorProps={{ $blockScrolling: true }}
/>
错误
拒绝从 '...../worker-json.js' 执行脚本,因为它的 MIME 类型 ('text/html') 不可执行。(匿名)@ 2f896707-86be-497a-93b2-e1711942d7c7:1 2f896707-86be-497a-93b2-e1711942d7c7:1 未捕获的 DOMException:无法在 'WorkerGlobalScope' 上执行 'importScripts':脚本位于 '...../ worker-json.js' 加载失败。
如何使用 JSON?
解决方案
尝试设置选项useWorker: false
<AceEditor
mode="json"
theme="github"
onChange={onChange}
name="UNIQUE_ID_OF_DIV"
editorProps={{ $blockScrolling: true }}
setOptions={{
useWorker: false
}}
/>
推荐阅读
- google-cloud-nl - Google AutoML 自然语言多标签文本分类的输入数据集格式
- javascript - 异步/等待调用功能的最佳方式?
- java - 根据用户输入更改 ImageView
- c# - 如何使用 ASP.NET 从 Select 标记中获取数据并插入到 Input 标记中
- android - 将捆绑包设置为意图 URL
- node.js - 嗨,我在一个数组中有 209580 个对象,如何使用 mongoose 在 MongoDB 中一次保存所有对象?
- docker - Jenkins Pipeline Docker——容器未运行
- outlook-addin - 在 OfficeJS 中,如果我们对多个文件使用 addFileAttachmentAsync 函数,回调只运行一个
- performance - Solr 的 spellcheck.collate 如何影响性能?
- javascript - 在不使用 websockets 的情况下管理服务器上的在线用户