小编Chi*_*dex的帖子

从对象渲染 SVG

我正在开发一个 React 项目,并且尝试从对象数组中渲染 SVG。然而,每当我尝试从地图方法访问 SVG 时,我都会收到错误。有没有更好的方法来完成我所缺少的过程。对于上下文:

\n
locations: [\n            { svg: SanFrancisco, city: "San Francisco, CA", number: 54 },\n            { svg: Redwood, city: "Redwood City, CA", number: 1 },\n            { svg: NewYork, city: " New York, NY", number: 17 },\n            { svg: Portland, city: "Portland, OR", number: 10 }\n           ]\n
Run Code Online (Sandbox Code Playgroud)\n

SVG 已在此处作为 React 组件导入。

\n

jsx中的用法:

\n
{locations.map((location) => {\n                            return (\n                                <a href="#">\n                                    {" "}\n                                    <div className="locations-card card">\n                                        {location.svg}\n                                        <h2>{location.city}</h2>\n                                        <p>{location.number} openings</p>\n                                    </div>\n                                </a>\n                            );\n                        })}\n
Run Code Online (Sandbox Code Playgroud)\n

将location.svg …

javascript arrays svg object reactjs

3
推荐指数
1
解决办法
2021
查看次数

标签 统计

arrays ×1

javascript ×1

object ×1

reactjs ×1

svg ×1