6
6
onMounted ,
7
7
onUnmounted ,
8
8
ref ,
9
+ useTemplateRef ,
9
10
watch ,
10
11
watchEffect ,
11
12
} from ' vue'
@@ -19,7 +20,7 @@ const props = defineProps<{ show: boolean; ssr: boolean }>()
19
20
const { store, clearConsole, theme, previewTheme, previewOptions } =
20
21
inject (injectKeyProps )!
21
22
22
- const container = ref < HTMLDivElement >( )
23
+ const containerRef = useTemplateRef ( ' container ' )
23
24
const runtimeError = ref <string >()
24
25
const runtimeWarning = ref <string >()
25
26
@@ -68,7 +69,7 @@ function createSandbox() {
68
69
// clear prev sandbox
69
70
proxy .destroy ()
70
71
stopUpdateWatcher && stopUpdateWatcher ()
71
- container .value ?.removeChild (sandbox )
72
+ containerRef .value ?.removeChild (sandbox )
72
73
}
73
74
74
75
sandbox = document .createElement (' iframe' )
@@ -101,7 +102,7 @@ function createSandbox() {
101
102
previewOptions .value ?.placeholderHTML || ' ' ,
102
103
)
103
104
sandbox .srcdoc = sandboxSrc
104
- container .value ?.appendChild (sandbox )
105
+ containerRef .value ?.appendChild (sandbox )
105
106
106
107
proxy = new PreviewProxy (sandbox , {
107
108
on_fetch_progress : (progress : any ) => {
@@ -280,7 +281,7 @@ function reload() {
280
281
sandbox .contentWindow ?.location .reload ()
281
282
}
282
283
283
- defineExpose ({ reload , container })
284
+ defineExpose ({ reload , container: containerRef })
284
285
</script >
285
286
286
287
<template >
0 commit comments