作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
嘿,我正在尝试将我自己的 svg 导入 antd -> Icon 组件
就像在 documentation但我有一个异常(exception)
InvalidCharacterError: Failed to execute 'createElement' on 'Document': The tag name provided ('/static/media/archive-solid.3c305173.svg') is not a valid name.
import React, { Component } from "react";
import { Layout, Menu, Icon } from "antd";
import ArchiveSVG from "../../../img/icons/archive-solid.svg";
const { Sider } = Layout;
class SideBar extends Component {
state = {
collapsed: false
};
onCollapse = collapsed => {
this.setState({ collapsed });
};
render() {
return (
<Sider
collapsible
collapsed={this.state.collapsed}
onCollapse={this.onCollapse}
>
<div className={styles.logo} />
<Menu theme="dark" defaultSelectedKeys={["1"]} mode="inline">
<Menu.Item key="4">
<Icon component={ArchiveSVG} />
<span>Products</span>
</Menu.Item>
</Menu>
</Sider>
);
}
}
最佳答案
import Icon from '@ant-design/icons';
import { ReactComponent as USAFlagIcon } from "./usa-flag.svg";
const USFlag = () => <Icon component={USAFlagIcon} />
同样要更改自定义图标的颜色,您需要删除 SVG 属性。 (我正在使用
svgo .. *
how to us it? *
config file )
关于svg - 如何将 svg 导入 antd -> Icon 组件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53322676/
我是一名优秀的程序员,十分优秀!