看了一些例子我設(shè)計了如下store一個頁面的總store,結(jié)構(gòu)如下// 頁面總的storeclass store { @observable list: [] @action async getData(){ const data = await axios.get('/getgoods'); this.list = data.map(item => new GoodsModel(this, item)); }}// 每個商品的modelclass GoodsModel { store; @observable price; @observable goodsName; @observable goodsImg; constructor(store, json){ this.store = store; this.goodsName = json.goods_name; this.goodsImg = json.img_url; this.price = json.price; }}每個單個商品的model只保存了屬于自己的信息,但是有時需要用到整個頁面store中的數(shù)據(jù),所有我在每個model中有一個store屬性,但是這樣設(shè)計在JSON.stringify()中就會報循環(huán)引用了,因為store中的list有model,model中又有store,這樣相互依賴的問題如何解決呢,請問mobx還有其他的設(shè)計思路嗎
mobx一個store設(shè)計的問題
慕妹3146593
2019-02-26 21:17:50