upgrade()
方法在
CustomElementRegistry
interface upgrades all shadow-containing custom elements in a
节点
subtree, even before they are connected to the main document.
customElements.upgrade(root);
root
节点
instance with shadow-containing descendant elements that are to be upgraded. If there are no descendant elements that can be upgraded, no error is thrown.
Void.
Taken from the HTML spec :
const el = document.createElement("spider-man");
class SpiderMan extends HTMLElement {}
customElements.define("spider-man", SpiderMan);
console.assert(!(el instanceof SpiderMan)); // not yet upgraded
customElements.upgrade(el);
console.assert(el instanceof SpiderMan); // upgraded!
| 规范 | 状态 | 注释 |
|---|---|---|
|
HTML 实时标准
The definition of 'customElements.upgrade()' in that specification. |
实时标准 | 初始定义。 |
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
upgrade
|
Chrome 68 | Edge 79 | Firefox 63 | IE 不支持 No | Opera 55 | Safari ? | WebView Android 68 | Chrome Android 68 | Firefox Android 63 | Opera Android 48 | Safari iOS ? | Samsung Internet Android 10.0 |
完整支持
不支持
兼容性未知
实验。期望将来行为有所改变。
CustomElementRegistry
define()
get()
upgrade()
whenDefined()