wechat-miniprogram / mobx-miniprogram-bindings

小程序的 MobX 绑定辅助库
MIT License
206 stars 20 forks source link

一个页面中可以绑定两个store么? #3

Closed jerryjiao closed 4 years ago

jerryjiao commented 4 years ago

一个页面中可以绑定两个store么?

jerryjiao commented 4 years ago

用两次createStoreBindings就行了,关闭了

callmesoul commented 4 years ago

@jerryjiao 发现不行啊

import { store } from '../../store'
import { store as shopStore } from '../../store/shop-detail'

 this.storeBindings = createStoreBindings(this, {
        store,
        fields: ['userInfo'],
    })
    this.storeBindings = createStoreBindings(this, {
      shopStore,
      fields: ['pets','shop'],
      actions: ['setPets'],
 })

报错

VM24173:1 thirdScriptError
[mobx-miniprogram] no store specified;at "pages/shop/detail" page lifeCycleMethod onLoad function
Error: [mobx-miniprogram] no store specified
    at _createActions (http://127.0.0.1:43542/appservice/miniprogram_npm/mobx-miniprogram-bindings/index.js:287:13)
    at createStoreBindings (http://127.0.0.1:43542/appservice/miniprogram_npm/mobx-miniprogram-bindings/index.js:400:5)
    at ye.onLoad (http://127.0.0.1:43542/appservice/pages/shop/detail.js:44:75)
    at ye.<anonymous> (WAService.js:1:1353019)
    at ye.p.__callPageLifeTime__ (WAService.js:1:1352764)
    at Tt (WAService.js:1:1367714)
    at WAService.js:1:1370885
    at xt (WAService.js:1:1371378)
    at Function.<anonymous> (WAService.js:1:1374768)
    at i.<anonymous> (WAService.js:1:1344283)

发现名字一定要store才行,换其他名字都会报错这个错,哪怕只有一个store 但是是固定用store的话,两个store就会冲突,换别名也报错

LastLeaf commented 4 years ago

改个名

this.storeBindings2 = createStoreBindings(this, {
      store: shopStore,
      fields: ['pets','shop'],
      actions: ['setPets'],
})
callmesoul commented 4 years ago

可以了,写法问题...

store: shopStroe