相关疑难解决方法(0)

如何在 Web 组件中使用 Material Design 图标?

看起来 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>
Run Code Online (Sandbox Code Playgroud)

https://codepen.io/Jamesgt/pen/MWwvJaw

web-component css-import native-web-component material-design-icons

5
推荐指数
1
解决办法
5655
查看次数