【发布时间】:2020-06-15 16:01:08
【问题描述】:
看起来 mdi 在 Web 组件中不起作用,还是我遗漏了什么?
我想开发一个web组件,封装了它的依赖,添加到父文档的链接是可行的,但是违背了初衷。
<html>
<body>
<x-webcomponent></x-webcomponent>
<script>
customElements.define(
"x-webcomponent",
class extends HTMLElement {
constructor() {
super();
this.attachShadow({ mode: "open" });
this.shadowRoot.innerHTML = `
<style>@import url('https://cdn.materialdesignicons.com/4.9.95/css/materialdesignicons.min.css');</style>
<span class="mdi mdi-home"></span>
`;
}
}
);
</script>
</body>
</html>
【问题讨论】:
-
看起来 css
@import不起作用,我猜是因为它还引用了其他资源...... -
在主文档中也添加
-
谢谢,编辑了问题,外部文档中的
<link>有帮助,但我觉得它不是一个优雅的解决方案。 -
也许看起来不优雅,但它是目前唯一使用字体的解决方案......
标签: web-component native-web-component css-import material-design-icons