We're looking for a user researcher to understand the needs of developers and designers. Is this you or someone you know? Check out the post: https://mzl.la/2IGzdXS

自定义元素注册表

草案
本页尚未完工.

CustomElementRegistry接口提供注册自定义元素和查询已注册元素的方法。

这是一个实验中的功能
此功能某些浏览器尚在开发中,请参考浏览器兼容性表格以得到在不同浏览器中适合使用的前缀。由于该功能对应的标准文档可能被重新修订,所以在未来版本的浏览器中该功能的语法和行为可能随之改变。

方法

CustomElementRegistry.define()
定义一个新的 自定义元素
CustomElementRegistry.get()
返回指定自定义元素的构造函数,如果未定义自定义元素,则返回undefined
CustomElementRegistry.whenDefined()
返回当使用给定名称定义自定义元素时将会执行的promise。(如果已经定义了这样一个自定义元素,那么立即履行返回的 promise。)

示例

JS 文件:

// `window.customElements` is an instance of `CustomElementRegistry`
window.customElements instanceof CustomElementRegistry // true

规范

Specification Status Comment
HTML Living Standard
CustomElementRegistry
Living Standard Initial definition.

浏览器兼容

FeatureChromeEdgeFirefoxInternet ExplorerOperaSafari
Basic support54 No1

592

Yes — 593

No4110.1
Support for Customized built-in elements66 No

592

Yes — 593

No53 No
define

664

545

No1

592

Yes — 593

No

534

415

10.16
get

664

545

No1

592

Yes — 593

No

534

415

10.16
whenDefined

664

545

No1

592

Yes — 593

No

534

415

10.16
FeatureAndroid webviewChrome for AndroidEdge mobileFirefox for AndroidOpera AndroidiOS SafariSamsung Internet
Basic support5454 No1

592

Yes — 593

4110.16.0
Support for Customized built-in elements6666 No

592

Yes — 593

53 No No
define

664

545

664

545

No1

592

Yes — 593

534

415

10.166.05
get

664

545

664

545

No1

592

Yes — 593

534

415

10.166.05
whenDefined

664

545

664

545

No1

592

Yes — 593

534

415

10.166.05

1. Under consideration

2. From version 59: this feature is behind the dom.webcomponents.customelements.enabled preference (needs to be set to true). To change preferences in Firefox, visit about:config.

3. Until version 59 (exclusive): this feature is behind the dom.webcomponents.enabled preference (needs to be set to true) and the dom.webcomponents.customelements.enabled preference (needs to be set to true). To change preferences in Firefox, visit about:config.

4. Support for 'Customized built-in elements' as well.

5. Support for 'Autonomous custom elements' only.

6. Supports 'Autonomous custom elements' but not 'Customized built-in elements'

文档标签和贡献者

此页面的贡献者: zhangchen, SphinxKnight, Ende93, fsx950223, xrr2016
最后编辑者: zhangchen,