plain.html 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <!doctype html>
  2. <html lang="zh-CN">
  3. <head>
  4. <meta charset="utf-8" />
  5. <meta name="viewport" content="width=device-width, initial-scale=1" />
  6. <title>跨框架演示:纯 HTML 直接用 &lt;quote-calc&gt;</title>
  7. <base href="/core-wc/wc/" />
  8. <!-- 本地开发改用 <script type="importmap" src="../importmap.json"><\/script> -->
  9. <script type="importmap" src="/npm/importmap/lit-v3.json"></script>
  10. <style>
  11. body { font-family: system-ui, sans-serif; margin: 24px; background: #f7fafc; }
  12. quote-calc { max-width: 420px; --qc-accent: #2f855a; }
  13. p.note { color: #718096; max-width: 520px; }
  14. </style>
  15. </head>
  16. <body>
  17. <h1>纯 HTML 宿主(无任何框架)</h1>
  18. <p class="note">
  19. 与本目录外的 Lit 页面用的是**同一个** <code>quote-calc.js</code> 和同一个 core。
  20. 这里没有 Lit 应用、没有路由、没有构建,只用标准 Web Component。
  21. </p>
  22. <quote-calc discount="0.1">
  23. <span slot="title">纯 HTML 里的报价组件</span>
  24. </quote-calc>
  25. <script type="module">
  26. import '../wc/index.js'; // 注册 <quote-calc>
  27. const el = document.querySelector('quote-calc');
  28. // 复杂值走 property(attribute 只能传字符串)
  29. el.items = [
  30. { sku: 'PLAIN-01', price: 30, qty: 2 },
  31. { sku: 'PLAIN-02', price: 5.5, qty: 4 },
  32. ];
  33. // 宿主可监听语义事件(composed,从 Shadow DOM 穿透出来)
  34. el.addEventListener('quote-done', (e) => console.log('quote-done', e.detail));
  35. el.addEventListener('quote-error', (e) => console.warn('quote-error', e.detail));
  36. </script>
  37. </body>
  38. </html>