【发布时间】:2020-03-25 18:09:01
【问题描述】:
在第一个组件中,我使用道具源发送到图像 svg:
<IconComponent :imgIcon="'../../assets/img/icon-example.svg'" />
接下来,当我得到道具时,我有第二个组件:
<img svg-inline :src="imgIcon" alt="icon">
export default {
name: 'IconComponent',
props: {
imgIcon: {
type: String,
required: true
}
}
};
但库 vue-svg-inline-loader 无法将 img 转换为 svg。
我有:
当我在第二个组件中更改为:
<img svg-inline src="../../assets/img/icon-example.svg" alt="icon">
然后图像正确转换为 svg。
编辑:
我补充说:
<object :data="require(`@/assets/img/${this.name}.svg`)" type="image/svg+xml"></object>
图像转换成 svg,我在 DOM 中有这个结构。
.icon {
margin: 0 map-get($margins, m1);
display: flex;
align-items: center;
height: 100%;
object svg g g {
fill: red;
}
}
但不会将颜色变为红色。
【问题讨论】: