-
Notifications
You must be signed in to change notification settings - Fork 0
/
omi-counter-simple-demo.html
57 lines (46 loc) · 1.37 KB
/
omi-counter-simple-demo.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
<!DOCTYPE html>
<html lang="zh-Hans">
<head>
<meta charset="utf-8">
<meta name="renderer" content="webkit|ie-comp|ie-stand"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Omi</title>
<link href="https://cdn.bootcss.com/normalize/7.0.0/normalize.min.css" rel="stylesheet">
<link href="https://cdn.bootcss.com/tailwindcss/0.7.3/utilities.min.css" rel="stylesheet">
<style type="text/css">
</style>
</head>
<body>
<div class="pl-5">omi-counter</div>
<script src="https://unpkg.com/omi"></script>
<script>
const { define, WeElement, html, render } = Omi
define('my-counter', class extends WeElement {
install() {
this.data.count = 1
this.sub = this.sub.bind(this)
this.add = this.add.bind(this)
}
sub() {
this.data.count--
this.update()
}
add() {
this.data.count++
this.update()
}
render() {
return html`
<div>
<button onClick=${this.sub}>-</button>
<span className="ml-10">${this.data.count}</span>
<button onClick=${this.add}>+</button>
</div>
`
}
})
render(html`<my-counter />`, 'body')
</script>
</body>
</html>