【发布时间】:2017-10-29 08:49:46
【问题描述】:
我收到以下错误:
proxyConsole.js:54 Error: [mobx] Invariant failed: Since strict-mode is enabled, changing observed observable values outside actions is not allowed. Please wrap the code in an `action` if this change is intended. Tried to modify: ObservableObject@1.items
at invariant (mobx.module.js:2326)
at fail (mobx.module.js:2321)
at checkIfStateModificationsAreAllowed (mobx.module.js:2890)
at ObservableValue../node_modules/mobx/lib/mobx.module.js.ObservableValue.prepareNewValue (mobx.module.js:796)
at setPropertyValue (mobx.module.js:1673)
at Object.set [as items] (mobx.module.js:1641)
at Store.js:41
at <anonymous>
但我将函数包装在 action 中,所以我有点困惑:
import { observable, useStrict, action } from 'mobx';
import Services from './Services';
// ...
getAllTodos: action(() => {
Services.getAllTodos()
.then((response) => {
state.items = response.data;
}).catch((error) => {
console.error(error);
});
}),
Services.js
// ...
getAllTodos () {
return axios.get(root + '/items/');
}
我在这里错过了什么?
【问题讨论】:
标签: javascript reactjs ecmascript-6 mobx