React SVG 导入作为组件不呈现 [英] React SVG import as a Component does not render

查看:41
本文介绍了React SVG 导入作为组件不呈现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 React JS 中导入 SVG 文件时遇到问题.

I'm having a problem with importing SVG files in React JS.

import { ReactComponent as Logo} from '../logo.svg'

我不知道为什么,但在某些组件中 会正确呈现而在其他组件中它没有显示,当我使用检查时 SVG 就在那里,它确实占用了它需要的空间,但 SVG 是空白/空的.

i don't know why but in some components <Logo /> will render correctly while in other components it doesn't show, the SVG is there when i use inspect and it does take the space it needs but the SVG is blank / empty.

还有其他人遇到过这个问题吗?

anyone else encountered this issue?

推荐答案

尝试:

import { default as logo } from '../logo.svg';

并在 img 类型的节点中用作源,如下所示:

and use as source in a node of type img, like this:

<img src={logo} />

这篇关于React SVG 导入作为组件不呈现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆