reactjs - SVG use variables with ReactJS
问题描述
Is there a way to use variables with SVG in ReactJS? 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.
解决方案
在 react 中绘制 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>
)
}
推荐阅读
- javascript - 在 HTML 数据属性中将 PHP 数组编码为 JSON 表示
- excel - 自动过滤工作表列表并删除标记的工作表并从示例工作表创建新的更新工作表
- c++ - MPI 上的矩阵向量乘法 - 错误编译代码
- c - CS50 信用问题 为什么万事达卡号应该无效
- cassandra-3.0 - Cassandra - 迁移数据文件夹(更改配置中的 data_file_directories 值)
- c# - 大括号之间的 C# 匿名数组
- angular - 如何在 Angular 测验应用程序中显示选项 1 的解释?
- sas - VARMAX 中的缺失值
- c++ - 获取 0xC0000005 访问冲突错误并不确定如何修复它
- c# - 如何显示来自控制器的值?