[英]How do I define svg attributes in virtual-dom?
Is there a way to add svg attributes to nodes using virtual-hyperscript in virtual dom? 有没有一种方法可以在虚拟dom中使用virtual-hyperscript向节点添加svg属性? For example, something like this: 例如,如下所示:
var h = require('virtual-dom/h')
h('svg', [
h('circle', {cx: 100, cy: 100}, 'some text')
])
I've tried to do this myself, but the attributes are removed on create
. 我自己尝试过执行此操作,但是在create
上删除了属性。
Turns out you do this: 原来你这样做:
h('circle', {namespace: "http://www.w3.org/2000/svg", attributes: {cx: 100}})
createElement
and createElementNS
as two different things even though they output the same html. 需要名称空间-这是因为浏览器将createElement
和createElementNS
视为两个不同的东西,即使它们输出相同的html。 Namespace is needed to differentiate it from a normal DOM element. 需要命名空间以将其与普通DOM元素区分开。 See: https://github.com/Matt-Esch/virtual-dom/tree/master/virtual-hyperscript#namespace 参见: https : //github.com/Matt-Esch/virtual-dom/tree/master/virtual-hyperscript#namespace
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.