繁体   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