为ember组件指定不同的模板路径



假设我有这样的结构:

modals/
├─ index.hbs
├─ base.ts
├─ new/
│  ├─ index.ts (extends base.ts)
├─ rename/
│  ├─ index.ts (extends base.ts)

(基本上我有两个组件有完全相同的模板,但不同的逻辑在.ts/.js文件)

是否可以在这两个索引中指定模板路径?Ts文件指向索引。哈佛商学院在上面一层?

或类似的东西,其思想是不必在这两个组件之间复制模板。

我已经尝试了上面的结构,但它似乎不工作。我想我必须在某个地方指定一个模板路径,但我只是在文档中找不到这样的东西。

不建议这么做。

对于非常低级的api是可能的(由于它们被编译成JS(ON)的性质),但是关于模板的一些事情需要理解的是,它们组件——而不是组件所拥有的

这在Ember即将到来的默认语法gjs/gts中变得更加清晰,证明:

import Component from '@glimmer/component';
import { tracked } from '@glimmer/tracking';
import { on } from '@ember/modifier';
export default class HelloWorld extends Component {
@tracked count = 0;
increment = () => this.count += 1;
<template>
<p>You have clicked the button {{this.count}} times.</p>
<button {{on "click" this.increment}}>Click</button>
</template>
}

你今天就可以试试这个插件:https://github.com/ember-template-imports/ember-template-imports/

最新更新