简体   繁体   English

SVG与ReactJS一起使用变量

[英]SVG use variables with ReactJS

Is there a way to use variables with SVG in ReactJS? 有没有办法在ReactJS中将变量与SVG一起使用? I want to draw a polyline, but the points always differ, so I could use variables for the points, but I can't seem to figure it out. 我想画一条折线,但是这些点总是不同的,所以我可以为这些点使用变量,但是我似乎无法弄清楚。

There's nothing special you need to do to draw SVG in react, just render it like any other JSX and use dynamic values (or values from props ) if you need to: 在反应中绘制SVG不需要做任何特殊的事情,只需像其他任何JSX一样渲染它,并在需要时使用动态值(或props值)即可:

render() {
  const cx = 10
  const cy = 10
  const r = 20

  return (
    <svg>
      <circle cx={cx} cy={cy} r={r} fill="red" />
    </svg>
  )
}

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

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