问题描述
我想使用Maquette作为基本的上标语言.因此,我不想使用maquette.projector
.但是,我很难使任何maquette.dom
函数正常工作.
I want to use Maquette as a basic hyperscript language. Consequently, I don't want to use the maquette.projector
. However, I'm having a hard time getting any of the maquette.dom
functions to work.
var h = maquette.h;
var dom = maquette.dom;
var svg = h('div.sweet', [
h('svg', [
h('circle', { cx: '2cm', cy: '2cm', r: '4cm', fill: 'red' }),
])
]);
document.addEventListener('DOMContentLoaded', function () {
console.log(svg);
var root = dom.create(svg).domNode;
});
<script src="//cdnjs.cloudflare.com/ajax/libs/maquette/2.4.1/maquette.min.js"></script>
我做错了什么?为什么dom.create
不呈现任何内容?
What am I doing wrong? Why is dom.create
not rendering anything?
推荐答案
很高兴看到您找到了没有投影仪的另一个用例. dom.create
方法仅创建DOM节点,但不会将其附加到文档中的任何位置.您可以使用document.body.appendChild(root)
或dom.append(document.body, svg)
.
Nice to see that you have found another usecase without the projector. The dom.create
method only creates the DOM nodes, but it does not append them anywhere in the document. You can use document.body.appendChild(root)
or use dom.append(document.body, svg)
.
这篇关于在没有投影仪的情况下渲染马奎特的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!