-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdemo.html
74 lines (67 loc) · 1.66 KB
/
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Template Demo</title>
<style>
.ok {
color: red;
font-weight: bold;
}
.yes {
font-size:20px;
}
</style>
</head>
<body>
<div id="app"></div>
</body>
</html>
<script src="./dist/template.min.js"></script>
<script>
const data={
html: "<marquee style='width:100px'>我是一条鱼</marquee>",
text: "<b>我是纯文本</b>",
ok: true,
child: {
yes: true,
no: false,
},
arr: [0, 1, 2],
citys: {
BJ: "北京",
SH: "上海",
GZ: "广州",
},
items: [
{ title: "吉林省", children: [{ name: "长春" }, { name: "延边" }], show: false },
{ title: "黑龙江省", show: true },
{ title: "辽宁省", show: true },
],
};
const content=`
<h3>if 判断</h3>
<div if="ok">I'm ok!</div>
<div else>I'm else!</div>
<h3>HTML 赋值</h3>
<div html="html"></div>
<h3>TEXT 赋值</h3>
<div text="text"></div>
<div>{{text}}</div>
<h3>:class 条件使用</h3>
<div :class="ok:ok|yes:child.yes">:class="ok:ok|yes:child.yes"</div>
<h3>遍历单一数组</h3>
<button for="a in arr">{{a}}</button>
<h3>遍历对象</h3>
<button for="city in citys by code">{{code}} : {{city}}</button>
<h3>遍历多维数组</h3>
<ul>
<li for="item in items">
{{$index}} - {{item.title}} <span style="color:red" if="!item.show" onclick="this.innerHTML=Date.now().toString(32).toUpperCase()">判断</span>
<ul if="item.children">
<li for="child in item.children">{{$index}} -{{child.name}}</li>
</ul>
</li>
</ul>`;
document.querySelector("#app").innerHTML = Template(content,data);
</script>