1
我想在React項目中使用Mobx(使用Meteor)並使用mobx-react
創建全局通知存儲。Mobx返回空對象
我嘗試初始化模塊,但我不知道爲什麼它返回一個空對象:
import { observable } from 'mobx';
class NotificationStore {
@observable notifications = ['test', 'new notification'];
}
var store = window.store = new NotificationStore;
export default store;
在我App.js:
import store from '../../components/NotificationStore';
console.log(store); // return Object { }
任何人都知道爲什麼我的對象是空的 ?
謝謝社區!
這很奇怪。它工作[**爲我**](http://jsbin.com/cenibayuyi/1/edit?js,console,output)。也許你會在代碼中的其他地方覆蓋'window.store'? – Tholle
嗨!在你的例子中,空的對象也是,nop? –
寫'store.notifications.toJS()',你會看到值。 – Tholle