diff --git a/pages/post/_id.vue b/pages/post/_id.vue index 90e23cb..5d0c1b4 100644 --- a/pages/post/_id.vue +++ b/pages/post/_id.vue @@ -101,7 +101,7 @@ export default { // 创建编辑器 if (process.client) { if (!window.editorObj && window.Vditor) { - const editorConfig = { + window.editorObj = new window.Vditor('editor', { toolbar: [ 'emoji', 'headings', @@ -143,13 +143,59 @@ export default { toolbarConfig: { pin: true }, + cache: { + enable: true + }, + placeholder: '我们书写的不是代码,而是人生' + }) + + window.editorReplyObj = new window.Vditor('editor-reply', { + toolbar: [ + 'emoji', + 'headings', + 'bold', + 'italic', + 'strike', + 'link', + 'list', + 'ordered-list', + 'outdent', + 'indent', + 'quote', + 'line', + 'code', + 'inline-code', + 'upload', + 'insert-before', + 'insert-after', + 'undo', + 'redo', + { + name: 'more', + toolbar: [ + 'table', + 'fullscreen', + 'edit-mode', + 'check', + 'both', + 'code-theme', + 'content-theme', + 'export', + 'outline', + 'preview', + 'format', + 'devtools' + ] + }], + height: 220, + toolbarConfig: { + pin: true + }, cache: { enable: false }, placeholder: '我们书写的不是代码,而是人生' - } - window.editorObj = new window.Vditor('editor', editorConfig) - window.editorReplyObj = new window.Vditor('editor-reply', editorConfig) + }) } const comments = this.comments @@ -343,19 +389,22 @@ export default { if (cancel) { this.replyID = null this.replyLastID = null - document.getElementById('comment').appendChild(editorReplyObject) + window.location.hash = '_' } else { this.replyID = id this.replyLastID = replyLastID document.getElementById('comment_ID_' + id).appendChild(editorReplyObject) const comment = this.commentsMap.get(replyLastID) window.editorReplyObj.setValue('', true) - window.editorReplyObj.focus() - if (replyLastID !== null) { - window.editorReplyObj.insertValue('> ' + comment.comment_content + ' \n\n\n', true) - // window.editorReplyObj.getCursorPosition() - // window.editorReplyObj.setSelectionRange(pos, pos) - } + this.$nextTick(() => { + window.editorReplyObj.focus() + if (replyLastID !== null) { + window.editorReplyObj.insertValue('> ' + comment.comment_content + ' \n\n\n', true) + } else { + window.editorReplyObj.insertValue('', true) + } + window.location.hash = '#comment_ID_' + id + }) } } },