Last active
October 16, 2023 23:39
-
-
Save kuc-arc-f/81721f97acc5d54e9aa3c59c6b555fd3 to your computer and use it in GitHub Desktop.
preact + htm, app sample
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/preact.umd.js"></script> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/htm/3.0.4/htm.min.js"></script> | |
<script src="https://cdn.tailwindcss.com/3.3.2"></script> | |
<title>Custom Bootstrap Alerts Position</title> | |
</head> | |
<body class="bg-light"> | |
<div class="container"> | |
<h3 class="text-3xl font-bold">test12.html</h3> | |
<hr class="my-2" /> | |
<div id="root"></div> | |
<hr class="my-2" /> | |
<div id="root2"></div> | |
<div id="root3"></div> | |
</div> | |
<!-- CSS --> | |
<script src="./test12.js"></script> | |
</body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
console.log("test12.js"); | |
// | |
const html = htm.bind(preact.h); | |
const elem = document.getElementById("root"); | |
// | |
const li = []; | |
const data = ['hoge1', 'hoge2', 'hoge3']; | |
for (var i in data) { | |
li.push(html`<h1>Hello[ ${data[i]}] - 000</h1>`); | |
}; | |
preact.render(li, elem); | |
// | |
//root2 | |
// | |
const li2 = []; | |
li2.push(html`<h1 class="text-3xl">li_2</h1>`); | |
li2.push(html`<hr class="my-2" />`); | |
for (var i in data) { | |
li2.push(html`<h1>li2-Hello[ ${data[i]}] - 111</h1>`); | |
}; | |
li2.push(html`<hr class="my-2" />`); | |
preact.render(li2, document.getElementById("root2")); | |
// | |
//root3 | |
// | |
const li3 = []; | |
li3.push(html`<h1 class="text-3xl">li_3</h1>`); | |
li3.push(html`<hr class="my-2" />`); | |
for (var i in data) { | |
let htm = html` | |
<div> | |
<h1>li2-Hello[ ${data[i]}] - 111</h1> | |
<button id="btn_id_${i}">[ Test ]</button> | |
</div> | |
`; | |
li3.push(htm); | |
}; | |
li3.push(html`<hr class="my-2" />`); | |
preact.render(li3, document.getElementById("root3")); | |
//event | |
for (let i in data) { | |
const button= document.querySelector(`#btn_id_${i}`); | |
button.addEventListener('click', () => { alert(data[i])}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment