首先我簡單介紹下這是個代碼編輯器,不過遠沒有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方法點了
之后就可以將代碼格式化了,在這里我們直接檢查代碼長度,達到格式化的目的}}}}}