解决切换页面后编辑器异常

This commit is contained in:
yi-ge 2020-07-21 15:39:59 +08:00
parent 719e716c6f
commit ca2ec55a72

View File

@ -148,7 +148,9 @@ export default {
avatarURL: null,
email: null,
blog: null
}
},
editorObj: null,
editorReplyObj: null
}
},
mounted () {
@ -167,16 +169,25 @@ export default {
window.localStorage.visitorInfo = JSON.stringify(visitorInfo)
this.visitorToken = visitorToken
this.visitorInfo = visitorInfo
window.editorObj.vditor.options.upload.headers = {
this.editorObj.vditor.options.upload.headers = {
Authorization: 'Bearer ' + this.visitorToken
}
window.editorReplyObj.vditor.options.upload.headers = {
this.editorReplyObj.vditor.options.upload.headers = {
Authorization: 'Bearer ' + this.visitorToken
}
}
if (!window.editorObj && window.Vditor) {
this.initEditor()
}
this.$nextTick(() => {
if (this.$route.query.hash) {
setTimeout(() => {
window.location.hash = '#' + this.$route.query.hash
}, 50)
}
if (!this.editorObj && window.Vditor) {
this.initEditor()
}
})
this.setCommentMap()
}
@ -253,15 +264,6 @@ export default {
}
}
if (this.$route.query.hash) {
this.$nextTick(() => {
setTimeout(() => {
window.location.hash = '#' + this.$route.query.hash
console.log('#' + this.$route.query.hash)
}, 50)
})
}
try {
(adsbygoogle = window.adsbygoogle || []).push({}) // eslint-disable-line
} catch (_) { }
@ -290,7 +292,7 @@ export default {
}
}
window.editorObj = new window.Vditor('editor', {
this.editorObj = new window.Vditor('editor', {
toolbar: [
'emoji',
'headings',
@ -338,7 +340,7 @@ export default {
placeholder: '我们书写的不是代码,而是人生'
})
window.editorReplyObj = new window.Vditor('editor-reply', {
this.editorReplyObj = new window.Vditor('editor-reply', {
toolbar: [
'emoji',
'headings',
@ -495,13 +497,13 @@ export default {
this.replyLastID = replyLastID
document.getElementById('comment_ID_' + id).appendChild(editorReplyObject)
const comment = this.commentsMap.get(replyLastID)
window.editorReplyObj.setValue('', true)
this.editorReplyObj.setValue('', true)
this.$nextTick(() => {
window.editorReplyObj.focus()
this.editorReplyObj.focus()
if (replyLastID !== null) {
window.editorReplyObj.insertValue('> ' + comment.comment_content + ' \n\n\n', true)
this.editorReplyObj.insertValue('> ' + comment.comment_content + ' \n\n\n', true)
} else {
window.editorReplyObj.insertValue('', true)
this.editorReplyObj.insertValue('', true)
}
window.location.hash = '#comment_ID_' + id
})
@ -516,7 +518,7 @@ export default {
return
}
const editorObj = type === 'editor-reply' ? window.editorReplyObj : window.editorObj
const editorObj = type === 'editor-reply' ? this.editorReplyObj : this.editorObj
const content = editorObj.getValue()
if (!content || content === '\n') {