其实本质问题是iframe的事件传递问题
this.container 为iframe,由于componentDidMount无法表征ifram的渲染状态,采用延时执行,起始iframe本身是具有函数可用的;
函数内主要做两个操作;1点击iframe时,进行focus,使得事件可以传入iframe,并将monaco的编辑状态置为false
当mouseup时,开启编辑状态
componentDidMount(){ setTimeout( () => { let _document = this.container.contentWindow.parent.document let ele = _document.getElementsByClassName('inputarea')[0] this.container.contentWindow.document.addEventListener('click', () => { this.container.focus() ele.disabled = true }) this.container.contentWindow.document.addEventListener('keyup', e=> { ele.disabled = false }) },2000) }