-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
66 lines (56 loc) · 1.38 KB
/
index.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
.count {
cursor: pointer;
}
</style>
</head>
<body>
<div id="app"></div>
<script type="module">
import { h, reactive, watchEffect, mount, patch } from './dist/mini-vue.esm.js'
const App = {
data: reactive({
count: 0
}),
render() {
return h('div', {
class: 'count',
style: 'color:red;',
onClick: () => {
this.data.count++
const count = document.querySelector('.count')
if (Math.abs(this.data.count) % 2 === 0) {
count.style.color = 'blue'
} else {
count.style.color = 'red'
}
}
}, String(this.data.count))
}
}
function mountApp(component, container) {
let isMounted = false
let prevVom;
watchEffect(() => {
if (!isMounted) {
prevVom = component.render()
mount(prevVom, container)
isMounted = true
} else {
const newVdom = component.render()
console.log(prevVom, newVdom)
patch(prevVom, newVdom)
prevVom = newVdom
}
})
}
mountApp(App, document.getElementById('app'))
</script>
</body>
</html>