Skip to content

Commit

Permalink
fix: 🐛 use nextTick to defer execution after the DOM update circle
Browse files Browse the repository at this point in the history
  • Loading branch information
luthfimasruri committed Mar 23, 2021
1 parent e206e06 commit c6baa9b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
8 changes: 7 additions & 1 deletion docs/components/demo/DemoEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
{ value: '', label: 'None' },
]"
></VOptions>
<div>{{ selectedTheme }}</div>
</div>
<div class="text-sm text-gray-400 font-bold mb-2">TOOLBAR</div>
<div class="flex md:flex-col gap-2 mb-4">
Expand All @@ -26,6 +27,7 @@
{ value: '', label: 'None' },
]"
></VOptions>
<div>{{ selectedToolbar }}</div>
</div>
</div>
<div class="initial flex-1 flex flex-col">
Expand All @@ -46,7 +48,7 @@
<script lang="ts">
import { Quill } from "@vueup/vue-quill";
import { Delta } from "types-quill-delta";
import { defineComponent, onMounted, ref } from "vue";
import { defineComponent, watch, onMounted, ref } from "vue";
import VOptions from "../VOptions.vue";
import { deltaContent } from "./delta-content";
Expand Down Expand Up @@ -77,6 +79,10 @@ export default defineComponent({
const selectedTheme = ref<string>("snow");
const selectedToolbar = ref<string>("essential");
watch([selectedTheme, selectedToolbar], () => {
myEditor.value.reinit();
});
return {
selectedTheme,
selectedToolbar,
Expand Down
10 changes: 7 additions & 3 deletions src/components/QuillEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
defineComponent,
onBeforeUnmount,
onMounted,
nextTick,
PropType,
watch,
ref,
Expand Down Expand Up @@ -214,9 +215,12 @@ export default defineComponent({
}

const reinit = () => {
if (!ctx.slots.toolbar && quill)
quill.getModule("toolbar")?.container.remove();
initialize();
nextTick(() => {
if (!ctx.slots.toolbar && quill)
quill.getModule("toolbar")?.container.remove();
initialize();
console.log("reinit call");
})
}

watch(
Expand Down

0 comments on commit c6baa9b

Please sign in to comment.