Webcomponentjs polyfill for v1 spec

老子叫甜甜 提交于 2019-12-12 01:28:33

问题


Is there a polyfill for the Web Components v1 spec available? I'm looking for a way to create components using customElements.define instead of document.registerElement.


回答1:


As mentioned by @tony19, you can use v1 branch of webcomponentsjs. You can read about it here.

Or you can install it using bower

bower i -S webcomponentsjs#v1




回答2:


If you want to polyfill only Custom Elements v1 (implementing customeElements.define) you have the choice between 2 polyfills:

  • document-register-element
  • custom-elements

If you want to polyfill the whole Web Components stack, you can use the v1 branch of the webcomponentsjs polyfill, since the current release (v0.7.23) doesn't implement yet the Custom Element and Shadow DOM "v1" Living Standards. Note that it is not merged in the master yet and subject to changes.

You can also only load the useful polyfills depending of your needs:

  • Custom Elements v1: see above
  • HTML Imports: HTMLImport.js in the current webcomponentsjs release
  • Shadow DOM v1: ShadyDOM, and ShadyCSS
  • Templates (old browsers only :) Template.js in the current webcomponentsjs release


来源:https://stackoverflow.com/questions/41284705/webcomponentjs-polyfill-for-v1-spec

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!