我正在学习 Embercasts课程(Ember + Rails)。对于截屏视频,他们使用了 Ember 3.0,但我使用的是 Octane。
在一个视频中,实现了自定义服务。这是我的版本的样子:
import Service, { inject as service } from '@ember/service';
export default class CurrentUserService extends Service {
@service store;
load() {
this.store.queryRecord('user', { me: true })
.then((user) => {
this.set('user', user);
})
.catch((e) => {
debugger;
});
}
}
在load
从路由调用的函数中,this.store.queryRecord()
会导致错误:
TypeError: str.replace is not a function
at Cache.func (index.js:64)
at Cache.get (index.js:774)
at decamelize (index.js:167)
at Cache.func (index.js:32)
at Cache.get (index.js:774)
at Object.dasherize (index.js:190)
at UserAdapter.pathForType (json-api.js:221)
at UserAdapter._buildURL (-private.js:293)
at UserAdapter.buildURL (-private.js:275)
at UserAdapter.urlForQueryRecord (user.js:13)
相关线路是
var DECAMELIZE_CACHE = new _utils.Cache(1000, str => str.replace(STRING_DECAMELIZE_REGEXP, '$1_$2').toLowerCase());
这是UserAdapter
:
import ApplicationAdapter from './application';
export default class UserAdapter extends ApplicationAdapter {
urlForQueryRecord(query) {
if (query.me) {
delete query.me;
return `${super.buildURL(...arguments)}/me`;
}
return `${super.buildURL(...arguments)}`;
}
}
这里有什么问题?