Skip to content

Commit 705bff3

Browse files
committed
fix: fix codegen focus
1 parent 5985dd8 commit 705bff3

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

src/demo/CodeGen.vue

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ import {
66
onBeforeUnmount,
77
defineProps,
88
defineEmits,
9-
onMounted
9+
onMounted,
10+
nextTick
1011
} from "vue";
1112
import { useLocalStorage } from "@vueuse/core";
1213
import "highlight.js/styles/github.css";
@@ -53,17 +54,17 @@ const renderer = ref(props.renderer);
5354
const source = ref(null);
5455
watch(
5556
() => props.open,
56-
val => {
57+
async val => {
5758
if (val) {
5859
renderer.value = props.renderer;
5960
}
6061
61-
setTimeout(() => {
62-
if (initializing.value) {
63-
return;
64-
}
65-
source.value?.focus();
66-
});
62+
await nextTick();
63+
64+
if (initializing.value) {
65+
return;
66+
}
67+
source.value?.focus();
6768
}
6869
);
6970
@@ -78,6 +79,9 @@ onMounted(async () => {
7879
});
7980
8081
initializing.value = false;
82+
83+
await nextTick();
84+
8185
source.value?.focus();
8286
});
8387

0 commit comments

Comments
 (0)