示例工程 21-web-components
21-web-components/04-refactor-iife/index.html
点击「运行示例」后,左侧显示源码、右侧显示运行结果;console 输出会实时回传。
<!doctype html>
<html lang="zh-CN">
<head>
<meta charset="utf-8">
<title>21 · 重构 IIFE 计数器</title>
</head>
<body>
<p>第 09 章的 IIFE 计数器,现在是一个自定义元素:</p>
<x-iife-counter></x-iife-counter>
<script type="module">
import './x-iife-counter.js';
import { run } from './main.js';
const el = document.querySelector('x-iife-counter');
el.addEventListener('counter-reset-or-inc', (event) => {
console.log('事件 =>', event.detail.value);
});
run();
</script>
</body>
</html>