[英]Ember component life cycle hook method - Is it mandatory to call super?
[英]From within an ember component life cycle hook, how can I determine if the component is being invoked in block form?
根據Ember指南 ,您可以使用hasBlock
關鍵字確定是否從模板中以塊格式呈現組件:
// foo-component.hbs
{{#if hasBlock}}
block mode
{{else}}
something else
{{/if}}
我該如何在foo-component.js
執行此操作?
import Ember from 'ember';
export default Ember.Component.extend({
didInitAttrs: function() {
// hasBlock is not defined here
if ( this.get('hasBlock') ) {
}
}
});
您可以檢查Component的template
屬性,但是不建議使用這種行為:
if (this.get('template')) {
console.log('Component has block!');
}
根據sbatson的評論,不支持在模板中使用hasBlock
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.