J W*_*ezy 3 javascript ember.js
我正在升级到 Ember Octane,并且我知道 mixin 已被弃用。我将继续使用它们,直到我弄清楚如何更换它们。与此同时,我想将我的路线切换为使用新的类语法,而不是Route.extend. 新的路由类语法是否支持路由混合?如果是,怎么办?
这与Ember Octane Upgrade 如何将值从组件传递到控制器有关
余烬前辛烷值:
import Route from '@ember/routing/route';
import AbcAuthenticatedRouteMixin from '../../mixins/abc-authenticated-route-mixin';
export default Route.extend(AbcAuthenticatedRouteMixin, {
model() {
return {
oldPassword: '',
newPassword: '',
confirmPassword: ''
};
},
})
Run Code Online (Sandbox Code Playgroud)
余烬后辛烷值:
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
Run Code Online (Sandbox Code Playgroud)
原生类语法并不直接具有 Ember mixin 系统的等效语法。如果您想在转换为 Octane 时继续使用 mixin,可以通过将经典类扩展语法与本机类语法混合来实现:
尝试
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: ''
};
}
}
Run Code Online (Sandbox Code Playgroud)
此外,一些新的框架类,例如 Glimmer 组件,根本不支持 Ember mixins。未来mixins将会从框架中移除,不会直接替换。对于使用 mixins 的应用程序,建议的路径是将 mixins 重构为其他模式,包括:
纯原生类,通过类继承共享功能。可以在多个类中导入和使用的实用函数。可以注入多个类的服务,在它们之间共享功能和状态。
| 归档时间: |
|
| 查看次数: |
1608 次 |
| 最近记录: |