-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
64 lines (55 loc) · 1.86 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
<!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>
.test {
background-color: antiquewhite;
}
</style>
</head>
<body>
<div id="root"></div>
<!-- <script src="https://unpkg.com/react@18/umd/react.development.js" crossorigin></script>
<script src="https://unpkg.com/react-dom@18/umd/react-dom.development.js" crossorigin></script>
<script src="https://unpkg.com/@babel/standalone/babel.min.js" crossorigin></script> -->
<script src="../../.lib/[email protected]" crossorigin></script>
<script src="../../.lib/[email protected]" crossorigin></script>
<script src="../../.lib/[email protected]" crossorigin></script>
</body>
<script type="text/babel">
const list = [
{ id: 1, title: 'Cabbage', type: 'vegetable' },
{ id: 2, title: 'Garlic', type: 'vegetable' },
{ id: 4, title: 'Apple', type: 'fruit' }
]
// 循环 并根据 type 显示不同颜色
function Eg_JSXLoop() {
return (
<ul>
{
list.map((item) => (
<li key={item.id} style={{ color: item.type === 'vegetable' ? 'green' : 'red' }}>{item.title}</li>
))
}
</ul>
)
}
function MyApp() {
return (
<main>
<Eg_JSXLoop />
</main >
)
}
// 渲染到页面上
// 获取根元素
const rootEl = document.getElementById('root')
// 创建 ReactDOM 根实例
const rootIns = ReactDOM.createRoot(rootEl)
// 使用根实例渲染组件
rootIns.render(React.createElement(MyApp))
</script>
</html>