Skip to content

解决setHtml时editor还未创建导致编辑器不显示内容的bug #22

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions src/components/Editor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export default Vue.extend({
return {
curValue: '',
editor: null,
handles: []
};
},
props: ['defaultContent', 'defaultConfig', 'mode', 'defaultHtml', 'value'], // value 用于自定义 v-model
Expand All @@ -38,7 +39,12 @@ export default Vue.extend({
// 重置 HTML
setHtml(newHtml: string) {
const editor = this.editor as any;
if (editor == null) return;
if (editor == null) {
this.handles.push(() => {
this.setHtml(newHtml);
})
return
};
editor.setHtml(newHtml);
},

Expand All @@ -59,7 +65,11 @@ export default Vue.extend({
...defaultConfig,
onCreated: (editor) => {
this.editor = Object.seal(editor) as any; // 注意,一定要用 Object.seal() 否则会报错

// 解决setHtml时 editor还未创建的bug
while (this.handles.length > 0) {
const handle = this.handles.pop()
handle();
}
this.$emit('onCreated', editor);
if (defaultConfig.onCreated) {
const info = genErrorInfo('onCreated');
Expand Down