簡體   English   中英

Ember 僅擴展組件模板

[英]Ember extend just the component template

我正在使用 Ember JS 並且有一個稍微棘手的要求;

我必須擴展一個組件(不完全在我的控制之下)。 所以我打算使用組件JS,但希望模板在我的控制之下(即覆蓋組件提供的內容)

這可能嗎? Ember 支持嗎? 任何參考示例都會很棒。

您可以做的是創建一個新組件並從您想要擴展的組件進行擴展:

組件/你的組件/component.js

import Base from '../base-component/component.js;
export default Base.extend();

然后你在components/your-component/template.hbs中有你的自定義模板,它使用來自基本組件的 JS 代碼。

我不得不使用稍微奇怪的路徑進行擴展。 由於某種原因,僅使用文件夾路徑是不夠的。

// The file I was importing was called "component.js", in the "my-component" folder
import MyComponent from 'project/pods/components/my-component/component';

export default MyComponent.extend({
    ...
});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM