-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathiframe.html
96 lines (84 loc) · 2.33 KB
/
iframe.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Vue</title>
<style>
</style>
</head>
<body>
<div id="app"></div>
<script src="https://unpkg.com/[email protected]"></script>
<script>
(function () {
var Vframe = Vue.component('vframe', {
beforeUpdate () {
console.log('beforeUpdate', this.$slots.default)
this.app.children = Object.freeze(this.$slots.default)
},
created () {
console.log('created', this.$el)
},
beforeMount () {
console.log('beforeMount', this.$el)
},
mounted () {
console.log('mounted', this.$el)
},
beforeUpdate () {
console.log('beforeUpdate', this.$el)
},
updated () {
console.log('beforeUpdate', this.$el)
},
methods: {
update () {
// console.log('slots', this.$slots.default)
console.log('load', this.$el)
const children = this.$slots.default
const body = this.$el.contentDocument.body
const el = document.createElement('div') // we will mount or nested app to this element
body.appendChild(el)
const app = new Vue({
name: 'app',
data: {
children: Object.freeze(children)
},
render(h) {
return h('div', this.children)
},
})
app.$mount(el) // mount into iframe
this.app = app // cache instance for later updates
}
},
render (createElement) {
return createElement('iframe', {
on: {
load: this.update
}
})
}
})
Vue.component('foobar', {
render (createElement) {
return createElement('div', 'Hello World')
}
})
Vue.component('container', {
render (createElement) {
return createElement('div', this.$slots.default)
}
})
new Vue({
el: '#app',
render (_c) {
return _c('div',[_c('vframe',[_c('foobar')],1)],1)
}
})
})()
</script>
</body>
</html>