feat: example01 작성 완료
This commit is contained in:
37
example01.html
Normal file
37
example01.html
Normal file
@@ -0,0 +1,37 @@
|
||||
<!doctype html>
|
||||
<html lang="ko">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Simple Component 1</title>
|
||||
</head>
|
||||
<body>
|
||||
<div id="app"></div>
|
||||
<script>
|
||||
const $app = document.querySelector('#app');
|
||||
|
||||
let state = {
|
||||
items: ['item1', 'item2', 'item3', 'item4']
|
||||
}
|
||||
|
||||
const render = () => {
|
||||
const { items } = state;
|
||||
$app.innerHTML = `
|
||||
<ul>
|
||||
${items.map(item => `<li>${item}</li>`).join('')}
|
||||
</ul>
|
||||
<button id="append">추가</button>
|
||||
`;
|
||||
document.querySelector('#append').addEventListener('click', () => {
|
||||
setState({ items: [ ...items, `item${items.length + 1}` ] })
|
||||
})
|
||||
}
|
||||
|
||||
const setState = (newState) => {
|
||||
state = { ...state, ...newState };
|
||||
render();
|
||||
}
|
||||
|
||||
render();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user