Ember.js 如何解决Don';不要使用余烬';s函数原型扩展
我收到一个错误Ember.js 如何解决Don';不要使用余烬';s函数原型扩展,ember.js,ember-data,ember-cli,Ember.js,Ember Data,Ember Cli,我收到一个错误不要使用Ember的函数原型扩展Ember/没有函数原型扩展 我的代码是这样的 import JSONAPIAdapter from 'ember-data/adapters/json-api'; import $ from 'jquery'; import config from 'appName/config/environment'; export default JSONAPIAdapter.extend({ shouldReloadAll: function() {
不要使用Ember的函数原型扩展Ember/没有函数原型扩展
我的代码是这样的
import JSONAPIAdapter from 'ember-data/adapters/json-api';
import $ from 'jquery';
import config from 'appName/config/environment';
export default JSONAPIAdapter.extend({
shouldReloadAll: function() {
return false;
},
shouldBackgroundReloadRecord: function() {
return true;
},
namespace: 'api/v1',
host: window.location.origin,
coalesceFindRequests: true,
headers: function() {
// Reference https://github.com/DavyJonesLocker/ember-appkit-rails/issues/220
// Only set the X-CSRF-TOKEN in staging or production, since API will only look for a CSRF token on those environments
let csrfToken;
if (config.environment === 'staging' || config.environment === 'production') {
csrfToken = $('meta[name="csrf-token"]').attr('content');
}
let authorizationToken = 'Token ' + this.currentSession.get('token');
return {
'X-CSRF-TOKEN': csrfToken,
'Authorization': authorizationToken
};
}.property().volatile(),
handleResponse(status, headers, payload, requestData) {
if (this.isInvalid(status, headers, payload)) {
if (payload && typeof payload === 'object' && payload.errors &&
typeof payload.errors === 'object') {
return payload.errors = [payload.errors];
}
}
return this._super(status, headers, payload, requestData);
}
});
这是我的终端所指的代码行.property().volatile(),
我在谷歌上搜索过,但找不到与我的工作类似的示例。顺便说一句,我已经将我的余烬版本从1.13.13
更新为3.1.0
,这就是我收到错误的原因
请帮助我,余烬的.property()
已被弃用
而不是:
headers: function() {
// ...
}.property().volatile(),
…做:
headers: computed(function () {
// ...
}).volatile(),
还要在顶部添加计算导入:
import { computed } from '@ember/object';
当您看到这些eslint错误时,在google上搜索规则的名称,在本例中为ember/no function prototype extensions
。您将看到错误的描述以及如何修复:
volatile()在3.10中也被弃用