我正在使用react应用程序中的react-monaco-editor库来查看文档。
对于特定的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和height。我如何才能做到这一点?
我看过很多与monaco-editor相关的答案,但没有一个明确使用react-monaco-editor。
谢谢你的指点。
发布于 2020-10-03 17:29:24
width和height属性支持所有HTML参数值作为字符串。它们默认使用100%来填充整个可用空间。这样,您就可以将编辑器包装到div中,您可以为该div设置特定的动态大小,或者让它参与网格或框布局。
https://stackoverflow.com/questions/64108234
复制相似问题