有没有办法按照这种样式对导入到 react 中的 SVG 组件进行样式设置:
使用带样式的组件?我一直在将我的个人项目切换到带样式的组件,并且由于某种原因,样式无法在组件上显示。import { ReactComponent as Icon } from "./resources/somerandom.svg"
这是我尝试过的:
import { ReactComponent as Icon } from "./resources/somerandom.svg"
import styled from "styled-components"
const IconWrapper = styled.svg`
fill: white;
width: 20px;
`
const RandomComponent = () => (
<IconWrapper>
<Icon/>
</IconWrapper>
)
我知道我可以直接将样式传递给SVG组件,但我想要一个使用带样式组件的解决方案。如果这篇文章没有多大意义,那可能是因为我起床的时间比我记得的要长。感谢所有的帮助。
一只斗牛犬
红糖糍粑
随时随地看视频慕课网APP
相关分类