简体   繁体   English

为什么当我导入 svg 图标时,只呈现路径名字符串,而不是实际的 svg 图标?

[英]Why when I import a svg icon, only the pathname string is rendered, and not the actual svg icon?

I have a folder called icons inside assets folder, and inside icons , I have folders for different sizes, inside each one, I have a bunch of svg files, each containing a svg icon.我在assets文件夹中有一个名为icons的文件夹,在icons里面,我有不同大小的文件夹,在每个文件夹中,我有一堆svg文件,每个文件都包含一个svg图标。

I created an index.js file inside icons folder, and then from it, I imported a svg file, and then export it, but when I import it from another component, all I get is a string pathname, and not the actual svg .我在图标文件夹中创建了一个index.js文件,然后从它导入了一个svg文件,然后导出它,但是当我从另一个组件导入它时,我得到的只是一个字符串路径名,而不是实际的svg

Here's my folder structure这是我的文件夹结构

Here's inside each size folder这是每个尺寸文件夹内

Here's inside the index.js这是 index.js 的内部

The console.log shows this: static/media/assets/icons/12x12/arrow-down-12.svg console.log显示: static/media/assets/icons/12x12/arrow-down-12.svg

Note that, I also tried using require to import the svg .请注意,我还尝试使用require导入svg

In order to render the svg you need to pass it as a dynamic value to an image tag like this:为了呈现 svg,您需要将其作为动态值传递给图像标签,如下所示:

<img src={arrowDown12} alt="" >

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM