问题
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.jsin the current webcomponentsjs release - Shadow DOM v1: ShadyDOM, and ShadyCSS
- Templates (old browsers only :)
Template.jsin the current webcomponentsjs release
来源:https://stackoverflow.com/questions/41284705/webcomponentjs-polyfill-for-v1-spec