【发布时间】:2019-10-17 21:24:22
【问题描述】:
在 web 组件中包含 Vuetify 的 material-icons 样式的正确方法是什么,以便在没有任何父级外部链接的情况下在阴影中访问它(因为 web 组件没有 index.html)?
我的目标是这样的厕所:
vue-cli-service build --target wc --name my-element 'src/components/mycomponent.vue'
所以,所有的 css 库/图标都需要存在于 mycomponent.vue 中。
我尝试在组件模板中添加指向材质图标的链接
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Material+Icons">
我也尝试过使用page上的各种说明
然而,当 Web 组件包含在外部页面中时,似乎没有任何效果。您看到的只是图标名称的字母,而不是图标。
// main.js
import 'material-design-icons-iconfont/dist/material-design-icons.css' // Ensure you are using css-loader
import Vue from 'vue'
import Vuetify from 'vuetify'
Vue.use(Vuetify, {
iconfont: 'md'
})
这不起作用,因为 Web 组件不包含 Vue 实例。 (即在父 vue 应用程序中)。我只是在导出一个 .vue 组件。
我希望图标可以在 Web 组件中工作,而不会在父组件中产生任何外部依赖。
【问题讨论】:
-
您是否尝试过从
component.vue内部导入它,例如:<style>@import "material-design-icons-iconfont/dist/material-design-icons.css"; </style>? -
厌倦了它,但由于缺少依赖项而无法构建。说即使我安装了 css-loader 也不存在。
-
你必须告诉 webpack 使用 css loader webpack.js.org/loaders/css-loader
标签: vue.js web-component vuetify.js google-material-icons