我想用React绘制箭头。我发现支持maker-end,参见:React文档。它被称为markerEnd
而不是marker-end
。它期望一个'url(#markerArrow)'
,但在React中似乎无法工作。如何使用SVG和React制作箭头?
这是我的一种方法,在组件的子类渲染函数中:它绘制了线条,但没有箭头。
render() {
return(
<div>
<svg className='Line' style={{ height:height, width:width, top:top, left:left }}>
<defs>
<marker id="markerArrow" markerWidth="13" markerHeight="13" refX="2" refY="6"
orient="auto">
<path d="M2,2 L2,11 L10,6 L2,2" style={{fill: '#000000'}} />
</marker>
</defs>
<line x1={lx1} y1={ly1} x2={lx2} y2={ly2} markerEnd={ 'url(#markerArrow)' } style={{ stroke: 'red', strokeWidth: 2 }} />
</svg>
</div>
);
}