当我们在 Ember 中向它传递一个动作时,yield 会如何表现?
How does yield behave when we pass it an action in Ember?
我有以下代码:
组件模板
{{#link-to "user.profile" account.id disabled=user.online}}
{{yield}}
{{/link-to}}
模板
{{#my-component data=x}}
<button> MY BUTTON </button>
{{/my-component}}
我在不同的模板中使用该组件,我希望生成的元素有一个动作。我读过你可以像这样使用它,但我无法真正理解这种行为。
{{#link-to "user.profile" account.id disabled=user.online}}
{{yield (action "showModal")}}
{{/link-to}}
任何人都可以阐明这个主题吗?
这里是它的用法:
{{#my-component as |act|}}
<button onclick={{action act}}>Button</button>
{{/my-component}}
Here 正在忙乱。
了解更多:这里有一个good blog post。这是作者关于上下文组件的三篇文章之一。
我有以下代码:
组件模板
{{#link-to "user.profile" account.id disabled=user.online}}
{{yield}}
{{/link-to}}
模板
{{#my-component data=x}}
<button> MY BUTTON </button>
{{/my-component}}
我在不同的模板中使用该组件,我希望生成的元素有一个动作。我读过你可以像这样使用它,但我无法真正理解这种行为。
{{#link-to "user.profile" account.id disabled=user.online}}
{{yield (action "showModal")}}
{{/link-to}}
任何人都可以阐明这个主题吗?
这里是它的用法:
{{#my-component as |act|}}
<button onclick={{action act}}>Button</button>
{{/my-component}}
Here 正在忙乱。
了解更多:这里有一个good blog post。这是作者关于上下文组件的三篇文章之一。