印刷< svg>内部< img>关于反应

发布于 2025-01-29 05:10:54 字数 874 浏览 1 评论 0原文

您好,我试图用SVG制作小应用程序。 我有一个返回SVG和其他信息的请求。

[
  {
    "svg": "<svg \n  xmlns=\"http://www.w3.org/2000/svg\"\n  class=\"h-6 w-6\"\n  fill=\"none\"\n  viewBox=\"0 0 24 24\"\n  stroke=\"currentColor\"\n  stroke-width=\"2\"\n>\n  <path \n  stroke-linecap=\"round\"\n  stroke-linejoin=\"round\"\n  d=\"M11 19l-7-7 7-7m8 14l-7-7 7-7\"\n  />\n</svg>",
  }
]

获得SVG值

  useEffect(() => {
    getSummaryWarnings().then((res) => {
      setData(res.data);
    });
  }, []);

打印IMG

 {data.map((item) => (
          <img
            tabIndex={0}
            key={item._id}
            className="warning-sign"
            alt={item.title}
            src={item.svg}
            onClick={() => tooglePopup(item)}
          />
        ))}

,但我看不到我的SVG。 任何帮助。

Hello I am trying to make small app with svgs.
I have a request that returns svg and other informations.

[
  {
    "svg": "<svg \n  xmlns=\"http://www.w3.org/2000/svg\"\n  class=\"h-6 w-6\"\n  fill=\"none\"\n  viewBox=\"0 0 24 24\"\n  stroke=\"currentColor\"\n  stroke-width=\"2\"\n>\n  <path \n  stroke-linecap=\"round\"\n  stroke-linejoin=\"round\"\n  d=\"M11 19l-7-7 7-7m8 14l-7-7 7-7\"\n  />\n</svg>",
  }
]

Getting svg value

  useEffect(() => {
    getSummaryWarnings().then((res) => {
      setData(res.data);
    });
  }, []);

Printing the img

 {data.map((item) => (
          <img
            tabIndex={0}
            key={item._id}
            className="warning-sign"
            alt={item.title}
            src={item.svg}
            onClick={() => tooglePopup(item)}
          />
        ))}

But i cant see my svg.
Any help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

疯到世界奔溃 2025-02-05 05:10:54

我找到了一个替代解决方案:

我们可以用这个打印SVG

<div
            tabIndex={0}
            key={item._id}
            className="warning-sign"
            alt={item.title}
            onClick={() => tooglePopup(item)}
            dangerouslySetInnerHTML={{ __html: item.svg }}
          />

I found an alternative solution:

We can print svg with this

<div
            tabIndex={0}
            key={item._id}
            className="warning-sign"
            alt={item.title}
            onClick={() => tooglePopup(item)}
            dangerouslySetInnerHTML={{ __html: item.svg }}
          />
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文