1
- import { h , ref , createApp , onMounted , onBeforeUpdate } from 'vue' ;
1
+ import { h , ref , createApp , onMounted , onBeforeUpdate } from 'vue' ;
2
2
3
3
export default {
4
4
name : 'RenderToIFrame' ,
@@ -7,21 +7,18 @@ export default {
7
7
type : String ,
8
8
default : '' ,
9
9
} ,
10
- scriptUrl : {
11
- type : String ,
12
- default : '' ,
13
- } ,
14
10
} ,
15
11
setup ( props , { slots } ) {
16
12
const iframeRef = ref ( null ) ;
17
13
const iframeBody = ref ( null ) ;
18
14
const iframeHead = ref ( null ) ;
19
15
const iframeCSS = ref ( null ) ;
20
- const iframeScript = ref ( null ) ;
21
16
const iframeStyle = ref ( null ) ;
22
17
let iframeApp = null ;
23
18
24
- onMounted ( ( ) => {
19
+ onMounted ( async ( ) => {
20
+ const tailwindCss = await import ( '../tailwind.css' ) ;
21
+
25
22
iframeBody . value = iframeRef . value . contentDocument . body ;
26
23
iframeHead . value = iframeRef . value . contentDocument . head ;
27
24
const el = document . createElement ( 'div' ) ;
@@ -32,7 +29,7 @@ export default {
32
29
iframeHead . value . appendChild ( iframeCSS . value ) ;
33
30
iframeStyle . value = document . createElement ( 'style' ) ;
34
31
iframeStyle . value . innerHTML =
35
- 'body { margin: 0; padding: 10px; background: #f8f9fa; }' ;
32
+ 'body { margin: 0; padding: 10px; background: #f8f9fa; }' + tailwindCss . default ;
36
33
iframeHead . value . appendChild ( iframeStyle . value ) ;
37
34
38
35
iframeApp = createApp ( {
@@ -42,21 +39,14 @@ export default {
42
39
} ,
43
40
} ) . mount ( el ) ;
44
41
} ) ;
42
+
45
43
onBeforeUpdate ( ( ) => {
46
44
if ( ! iframeApp || ! iframeRef . value ) {
47
45
return ;
48
46
}
49
47
iframeCSS . value . href = props . cssUrl ;
50
- if ( props . scriptUrl ) {
51
- iframeScript . value = document . createElement ( 'script' ) ;
52
- iframeScript . value . id = 'custom-script' ;
53
- iframeScript . value . src = props . scriptUrl ;
54
- iframeHead . value . appendChild ( iframeScript . value ) ;
55
- } else {
56
- document . getElementById ( 'custom-script' ) ?. remove ( ) ;
57
- iframeScript . value = null ;
58
- }
59
48
} ) ;
49
+
60
50
return ( ) => h ( 'iframe' , { ref : iframeRef } ) ;
61
51
} ,
62
52
} ;
0 commit comments