init: 示例工程
This commit is contained in:
commit
65d4dc3f21
3
README.md
Normal file
3
README.md
Normal file
@ -0,0 +1,3 @@
|
||||
# simple-web
|
||||
|
||||
最小前端示例:`index.html` + `app.js` + `style.css`,按钮点击后调用 `createOrder` 并渲染列表。
|
||||
16
app.js
Normal file
16
app.js
Normal file
@ -0,0 +1,16 @@
|
||||
// 最小前端示例:按钮 → 下单 → 渲染列表
|
||||
const orders = [];
|
||||
|
||||
function createOrder(sku, quantity) {
|
||||
return { id: `ORD-${sku}-${orders.length + 1}`, sku, quantity };
|
||||
}
|
||||
|
||||
function render() {
|
||||
const list = document.getElementById('list');
|
||||
list.innerHTML = orders.map(o => `<li>${o.id} × ${o.quantity}</li>`).join('');
|
||||
}
|
||||
|
||||
document.getElementById('btn').addEventListener('click', () => {
|
||||
orders.push(createOrder('SKU-001', 1));
|
||||
render();
|
||||
});
|
||||
15
index.html
Normal file
15
index.html
Normal file
@ -0,0 +1,15 @@
|
||||
<!doctype html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<title>Simple Web Demo</title>
|
||||
<link rel="stylesheet" href="style.css" />
|
||||
</head>
|
||||
<body>
|
||||
<h1>Simple Web Demo</h1>
|
||||
<p id="hint">点击按钮调用本地函数</p>
|
||||
<button id="btn">下单</button>
|
||||
<ul id="list"></ul>
|
||||
<script src="app.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
Loading…
Reference in New Issue
Block a user