Created
November 30, 2020 07:48
-
-
Save ayaysir/321b0c3b486a6d65f62e12c977c8d2da to your computer and use it in GitHub Desktop.
dynamic module import example
This file contains 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
let currentIdx = 1 | |
export function add() { | |
const $ul = document.getElementById("todo-list") | |
const $li = document.createElement("li") | |
$li.textContent = `할 일 ${currentIdx++}` | |
$ul.appendChild($li) | |
} |
This file contains 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="ko"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Document</title> | |
</head> | |
<body> | |
<button id="add-todo">할 일 추가</button> | |
<ul id="todo-list"></ul> | |
<script src="main.js" type="module"></script> | |
</body> | |
</html> |
This file contains 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
// import add from './add.js' | |
const onClick = e => { | |
import('./add.js').then(obj => { | |
obj.add() | |
}) | |
} | |
document.getElementById("add-todo").addEventListener("click", onClick) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment