我想在用户每次单击按钮时创建新的JavaScript组件-通过调用类似于Marko的DOM方法document.createElement("tag")。我如何在Marko中做到这一点,不仅仅是普通的HTML标记,还有自定义的Marko标记?
我尝试过的:document.createElement("custom-marko-component")
预期行为: Marko引擎编译自定义组件的新实例。
实际行为:浏览器生成了一个无用的新<custom-marko-component></custom-marko-component>。
发布于 2021-06-09 04:53:04
使用Marko的渲染函数(文档:https://markojs.com/docs/rendering/):
示例:
// Create the custom component, like document.createElement() but asynchronous.
// Import `./custom-marko-component.marko`
var customComponent = require("./custom-marko-component");
var resultPromise = customComponent.render({});
// Insert the custom component into the webpage.
resultPromise.then(result => {
result.appendTo(document.body);
});https://stackoverflow.com/questions/67894272
复制相似问题