问题描述
我正在升级到Ember Octane,并且我知道不推荐使用mixins。在确定替换方法之前,我将继续使用它们。同时,我想将路线切换为使用新的类语法,而不是 Route.extend
。新的路由类语法是否支持路由混合?如果是,怎么办?
I am upgrading to Ember Octane and I understand that mixins have been deprecated. I will continue to use them until I figure out how to replace them. In the meantime, I would like to switch my route over to using the new class syntax, as opposed to Route.extend
. Does the new route class syntax support route mixins? If yes, how?
这与
辛烷值:
import Route from '@ember/routing/route';
import AbcAuthenticatedRouteMixin from '../../mixins/abc-authenticated-route-mixin';
export default Route.extend(AbcAuthenticatedRouteMixin, {
model() {
return {
oldPassword: '',
newPassword: '',
confirmPassword: ''
};
},
})
后琥珀辛烷:
import Route from '@ember/routing/route';
import AbcAuthenticatedRouteMixin from '../../mixins/abc-authenticated-route-mixin';
export default class ChangePasswordRoute extends Route(AbcAuthenticatedRouteMixin, {
model() {
return {
oldPassword: '',
newPassword: '',
confirmPassword: ''
};
},
}) // I get an error here that says: '{' expected
推荐答案
本机类语法没有与Ember mixin直接对应的语法系统。如果要在转换为Octane时继续使用mixins,可以通过将经典类扩展语法与本机类语法混合来实现:
Native class syntax does not directly have an equivalent for the Ember mixin system. If you want to continue using mixins as you convert to Octane, you can do so by mixing classic class extension syntax with native class syntax:
尝试
import Route from '@ember/routing/route';
import AbcAuthenticatedRouteMixin from '../../mixins/abc-authenticated-route-mixin';
export default class ChangePasswordRoute extends Route.extend(AbcAuthenticatedRouteMixin) {
model() {
return {
oldPassword: '',
newPassword: '',
confirmPassword: ''
};
}
}
此外,还有一些新的框架类,例如Glimmer组件,根本不支持Ember mixins。将来,mixin将从框架中删除,并且不会直接替换。对于使用mixin的应用程序,建议的路径是将mixin重构为其他模式,包括:
In addition, some new framework classes, such as Glimmer components, do not support Ember mixins at all. In the future, mixins will be removed from the framework, and will not be replaced directly. For apps that use mixins, the recommended path is to refactor the mixins to other patterns, including:
这篇关于Ember Octane Route类是否支持使用mixins?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!