refactor: Remove useless react data and destory ace editor

This commit is contained in:
freedomlang 2019-12-05 17:36:29 +08:00 committed by Henrique Dias
parent 12d6415f7f
commit ae893abc5f
1 changed files with 4 additions and 8 deletions

View File

@ -18,10 +18,7 @@ export default {
...mapState(['req']) ...mapState(['req'])
}, },
data: function () { data: function () {
return { return {}
content: null,
editor: null
}
}, },
created () { created () {
window.addEventListener('keydown', this.keyEvent) window.addEventListener('keydown', this.keyEvent)
@ -30,16 +27,15 @@ export default {
beforeDestroy () { beforeDestroy () {
window.removeEventListener('keydown', this.keyEvent) window.removeEventListener('keydown', this.keyEvent)
document.getElementById('save-button').removeEventListener('click', this.save) document.getElementById('save-button').removeEventListener('click', this.save)
this.editor.destroy();
}, },
mounted: function () { mounted: function () {
if (this.req.content === undefined || this.req.content === null) { const fileContent = this.req.content || '';
this.req.content = ''
}
this.editor = ace.edit('editor', { this.editor = ace.edit('editor', {
maxLines: Infinity, maxLines: Infinity,
minLines: 20, minLines: 20,
value: this.req.content, value: fileContent,
showPrintMargin: false, showPrintMargin: false,
readOnly: this.req.type === 'textImmutable', readOnly: this.req.type === 'textImmutable',
theme: 'ace/theme/chrome', theme: 'ace/theme/chrome',