RIOT.JS - Yield
Yield 是一种将外部 HTML 内容放入 RIOT 标签的机制。有多种方法可以实现 yield。
简单 Yield − 如果我们要替换标签中的单个占位符,则使用此机制。
<custom3Tag> Hello <yield/> </custom3Tag>
<custom3Tag><b>User</b></custom3Tag>
多重 Yield − 如果我们要替换标签中的多个占位符,则使用此机制。
<custom4Tag> <br/><br/> Hello <yield from = "first"/> <br/><br/> Hello <yield from = "second"/> </custom4Tag>
<custom4Tag> <yield to = "first">User 1</yield> <yield to = "second">User 2</yield> </custom4Tag>
示例
以下是完整示例。
custom3Tag.tag
<custom3Tag> Hello <yield/> </custom3Tag>
custom4Tag.tag
<custom4Tag> <br/><br/> Hello <yield from = "first"/> <br/><br/> Hello <yield from = "second"/> </custom4Tag>
custom3.htm
<html> <head> <script src = "https://cdnjs.cloudflare.com/ajax/libs/riot/3.13.2/riot+compiler.min.js"></script> </head> <body> <custom3Tag><b>User</b></custom3Tag> <custom4Tag> <yield to = "first">User 1</yield> <yield to = "second">User 2</yield> </custom4Tag> <script src = "custom3Tag.tag" type = "riot/tag"></script> <script src = "custom4Tag.tag" type = "riot/tag"></script> <script> riot.mount("custom3Tag"); riot.mount("custom4Tag"); </script> </body> </html>
将生成以下结果 −
广告