我在一个示例应用程序中尝试webcomponents . 由于某些浏览器中不包含某些规格,我尝试使用polyfill . 在Mozilla firefox中,我尝试启用密钥dom.webcomponents.enabled并添加一些polyfill(不在浏览器中) . 我使用了webcomponents.js polyfill中的HTML Import polyfill .
HTMLImport还没有在firefox,Internet Explorer中工作(即使使用polyfill) . (https://github.com/webcomponents/webcomponentsjs)
我也尝试过customElements v1 polyfill,而不是在Internet Explorer和firefox中工作 . (https://github.com/webcomponents/custom-elements)
有没有人成功将HTMLimports polyfill与customElements V1 polyfill包括在一起?
1 回答
要在Firefox中使用带有HTML导入的自定义元素v1:
Do not 激活Firefox标志,因为实施已过时 .
安装 webcomponentsjs (例如使用bower),并在主文件中仅包含
htmlimports.min.js
文件 .安装 custom-elements (来自您的链接)并包含在主文件
custom-elements.min.js
中 .您的主页应如下所示:
注意:对于第3步,您也可以使用document-register-element .
您不能直接在Internet Explorer中使用自定义元素v1
class
语法,因为未实现class
. 您首先需要使用像Babel这样的转换器来转换源代码 .或者,使用现代版本(Edge),或使用
prototype
语法 .