gpt4 book ai didi

ember.js - 如何解决不要使用 Ember 的函数原型(prototype)扩展

转载 作者:行者123 更新时间:2023-12-02 06:02:01 26 4
gpt4 key购买 nike

我收到了 Don't use Ember's function prototype extensions ember/no-function-prototype-extensions 的错误

我的代码行是这样的

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 更新了我的 ember 版本至 3.1.0这就是我收到错误的原因。

请帮我

最佳答案

Ember 的 .property()已弃用。

代替:

headers: function() {
// ...
}.property().volatile(),

...做:
headers: computed(function () {
// ...
}).volatile(),

还要在顶部添加计算的导入:
import { computed } from '@ember/object';

当您看到这些 eslint 错误时,请在 Google 上搜索规则的名称,在本例中为 ember/no-function-prototype-extensions .您将找到错误的描述以及如何修复:

https://github.com/ember-cli/eslint-plugin-ember/blob/master/docs/rules/no-function-prototype-extensions.md

关于ember.js - 如何解决不要使用 Ember 的函数原型(prototype)扩展,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50734571/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com