
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>
將生成以下結果 −
廣告