【发布时间】:2023-03-26 19:50:01
【问题描述】:
我可以创建使用子标记的非空 Knockout 组件吗?
一个示例是用于显示模式对话框的组件,例如:
<modal-dialog>
<h1>Are you sure you want to quit?</h1>
<p>All unsaved changes will be lost</p>
</modal-dialog>
与组件模板一起:
<div class="modal">
<header>
<button>X</button>
</header>
<section>
<!-- component child content somehow goes here -->
</section>
<footer>
<button>Cancel</button>
<button>Confirm</button>
</footer>
</div>
输出:
<div class="modal">
<header>
<button>X</button>
</header>
<section>
<h1>Are you sure you want to quit?</h1>
<p>All unsaved changes will be lost</p>
</section>
<footer>
<button>Cancel</button>
<button>Confirm</button>
</footer>
</div>
【问题讨论】:
-
看看淘汰赛 3.3 - 它有你想要的。
标签: knockout.js knockout-components