javascript - 如何使用 react-monaco-editor 实现 Monaco 编辑器的动态调整大小?
问题描述
我正在使用react-monaco-editor
react 应用程序中的库查看文档。
height
对于特定的和,代码如下所示width
:
import MonacoEditor from 'react-monaco-editor';
class DocView extends React.Component<any, any> {
constructor(props){
super(props);
}
onChange(newValue, e) {
console.log('onChange', newValue, e);
}
public render(): JSX.Element {
const {t} = this.props;
const options = {
selectOnLineNumbers: true,
readOnly: true,
};
return (
<>
...
<div>
<MonacoEditor
width={900}
height={420}
language="yaml"
theme="vs-dark"
defaultValue=''
options={options}
value={this.props.code}
onChange={this.onChange}
/>
</div>
...
</>
);
}
}
我想根据窗口大小更改width
and 。height
我怎样才能做到这一点?
我已经看到了多个相关的答案,monaco-editor
但没有一个明确使用react-monaco-editor
.
感谢您的任何指示。
解决方案
和width
属性height
支持所有 HTML 参数值作为字符串。它们默认100%
填充整个可用空间。有了它,您可以将编辑器包装到您为其设置特定动态大小的 div 中,或者让它参与网格或框布局。
推荐阅读
- python - 为什么我可以在列表理解中使用 for 循环但没有 while 循环
- ember.js - 无法在 post.hbs 中绑定数据
- flutter - Flutter - 如何更改下拉项目列表的大小和对齐方式
- postgresql - 错误请使用 AWS Lambda 无服务器框架手动安装 pg 包
- sql - SQLCMD:使用powershell将带有数字的参数数据库startig传递给脚本
- reactjs - 在 iframe 中启用可编辑的 Google Doc
- mysql - Sequel Pro 连接到 Mysql 8.0 服务器没有列出数据库
- oracle - 如何将转储直接下载并导入到您的 oracle Docker 映像中?
- java - 存在检查构造函数有效输入的标准方法
- javascript - 使用 mongodb 中的 async/await 预保存保存地理编码器坐标