我遇到了错误 ReferenceError:找不到变量:authenticator Ember错误,并且在此代码中未在终端中定义 authenticator
import Controller from '@ember/controller';
import { inject } from '@ember/service';
export default Controller.extend({
session: inject('session'),
actions: {
authenticate: function(){
var credentials = this.getProperties('username','password');
authenticator = 'authenticator:jwt';
this.get('session').authenticate(authenticator,credentials).catch((reason) => {
this.set('errorMessage', reason.error || reason);
});
}
}
});
答案 0 :(得分:0)
正如@jelhan在评论中所说,您需要使用let来声明变量authenticator
。这是JavaScript的要求,而不是Ember的特定要求。
示例:
从'@ ember / controller'导入Controller;
import { inject } from '@ember/service';
export default Controller.extend({
session: inject('session'),
actions: {
authenticate: function(){
var credentials = this.getProperties('username','password');
let authenticator = 'authenticator:jwt';
this.get('session').authenticate(authenticator,credentials).catch((reason) => {
this.set('errorMessage', reason.error || reason);
});
}
}
});