我有一个模板字符串"<a onclick={ parent.foo }>Link</a>"
。我想将它传递给其他标签,然后正确渲染它。
我添加了我的代码的简短示例。它不起作用,只是试图展示我需要的东西。
<child-tag>
<div>{ opts.data }</div>
</child-tag>
<parent-tag>
<child-tag data={ html }></child-tag>
<script>
this.html = "<a onclick={ parent.foo }>Link</a>";
foo() {
console.log("Hello");
}
</script>
</parent-tag>
答案 0 :(得分:0)
Riot将逃脱你{h}的html { opts.data }
。您可以使用riot文档中描述的<raw>
标记。但最好是重写代码。
https://jsfiddle.net/nnyc688e/1/
<child-tag>
<yield/>
</child-tag>
<parent-tag>
<child-tag> <a onclick={ parent.foo }>Link</a> </child-tag>
foo() {
console.log("Hello");
}
</parent-tag>
这也更容易理解。