🔸custom element
browser ⟩ web components ⟩ implement ⟩ custom elements
⭐ custom element name 中間一定要有:"-
" ❗
例如:
<vstack->
或<v-stack>
✅但 "
-
" 不能放前面:<-vstack>
❌
define new custom elements with customElements.define().
custom elements render as inline elements by default.
Valid Custom Element Name
開頭:[a-z] ⭐️
接著:[0-9], [a-z], "
-
", ".
", "_
" (optional)中間一定要有:"
-
" ⭐️接著:[0-9], [a-z], "
-
", ".
", "_
" (optional)
<vstack-> 或 <i-vstack> ❓(這兩個都是合法的名字)
Register New Tag Name
We can create our tags by using the CustomElementRegistry object (window.customElements
).
custom element names must contain a hyphen❗ 📘 customElements.define()
Custom elements cannot be self-closing because HTML only allows a few elements to be self-closing. Always write a closing tag (
<custom-element></custom-element>
) 📘 Google ⟩ Custom Elements
Supporting Class
To create a custom element, we need to tell the browser several details about it: how to show it, what to do when the element is added or removed to page, etc.
Last updated