monaco代码编辑器


首先我简单介绍下这是个代码编辑器,不过远没有VScode那么强大,不过github上面给的东西实在实在实在本人看不太懂,并且邀了好多人也不是很懂.

总结了我自己用到的几个小玩意,如果你没有用到这个,建议你不要继续往下看了,浪费时间

monacoEditor = monaco.editor.create(document.getElementById('container'), {

         value:  "<div>我是插入的代码</div>" ,
         language:  'html' ,
         wrappingColumn: 0,
        wrappingIndent: "indent"
     });
if (monacoEditor) {
        monacoEditor.layout();
    }

如果你也有需要最大化代码编辑器的功能那么红色的代码是你需要的,
下面是我们经尝试不得已使用的格式化代码的方法,
codeJson是你的所有代码,
 
 
this.codeJson = this.sbIns.output()
this.model = monaco.editor.getModels()[0]
const timer = setInterval(() => {
if (this.model.getValueLength() > 0) {
clearInterval(timer)
this.editor.getAction('editor.action.formatDocument').run()
setTimeout(() => {
this.fullScreenLoading = false
}, 300)
}
}, 1000)
this.editor.setValue(JSON.stringify(this.codeJson))
绿色的是每次去检查代码的长度看是否执行方法将他格式化{{{{{{这个方法其实是代码上去之后,鼠标右击,这个插件写了个方法,出了个白色div里面有个formatdom方法点了
之后就可以将代码格式化了,在这里我们直接检查代码长度,达到格式化的目的}}}}}


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM