Using mixins with Ember-cli?

血红的双手。 提交于 2019-12-04 01:22:24
saygun

I don't know how do you export your mixin but this should work:

in mixins/ui-listener.js:

import Ember from 'ember';

export default Ember.Mixin.create({
 //some stuff
});

in components/my-component.js:

import Ember from 'ember';
import UIListenerMixin from '../mixins/ui-listener';

export default Ember.Component.extend(UIListenerMixin, {
 // some stuff
});

Instead of adding ../ (or even worse ../../../) into your imports, you can go to your config/environment.js and check for the property modulePrefix. Let's say the prefix is app-client.

Then, you can import by using import UIListen from 'app-client/mixins/ui-listener'; instead. Absolute works best if you are in a "deep" subroute, etc.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!