gpt4 book ai didi

javascript - React 组件提示 SVG 渐变样式?

转载 作者:行者123 更新时间:2023-11-29 19:03:46 25 4
gpt4 key购买 nike

我正在尝试将 SVG 转换为 React 组件,以便我可以在多个位置使用它。

这是来源

<svg height="1000px" width="1000px" class="logo-triangle">
<defs>
<linearGradient id="grad1" x1="0%" y1="100%" x2="100%" y2="0%">
<stop offset="0%" style="stop-color:rgb(50,50,50);stop-opacity:1"/>
<stop offset="100%" style="stop-color:black;stop-opacity:1"/>
</linearGradient>
</defs>
<filter id="dropshadow" height="130%">
<feGaussianBlur in="SourceAlpha" stdDeviation="3"/>
<feOffset dx="2" dy="2" result="offsetblur"/>
<feMerge>
<feMergeNode/>
<feMergeNode in="SourceGraphic"/>
</feMerge>
</filter>
<polygon points="500 474,0 106,495 0" stroke="#36e2f8" stroke-width="3"/>
</svg>

但是 React 似乎不喜欢 SVG 的 linearGradient 部分。

特别是这两行:

<stop offset="0%" style="stop-color:rgb(50,50,50);stop-opacity:1"/>
<stop offset="100%" style="stop-color:black;stop-opacity:1"/>

除非我删除这两行,否则该应用程序将无法运行,知道如何使用 JSX 编译器使其运行吗?

这是控制台的错误输出:

× The style prop expects a mapping from style properties to values, not a string. For example, style={{marginRight: spacing + 'em'}} when using JSX. This DOM node was rendered by Logo.

最佳答案

由于错误指出 style 属性的值应该是一个对象而不是字符串

试试这个:

<stop offset="0%" style={{stopColor:"rgb(50,50,50)", stopOpacity:1}} />
<stop offset="100%" style={{stopColor:"black", stopOpacity:1}} />

关于javascript - React 组件提示 SVG 渐变样式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44554440/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com