mobx-miniprogram-bindings
mobx-miniprogram-bindings copied to clipboard
可以在page和component中使用,那么如何在小程序的公用的js文件里面去取值和触发action
有没有大神
完蛋。。。
取值:
import {store} from './store.js'
console.log(store.xxx)
触发action
import { runInAction } from 'mobx-miniprogram'
import { store } from './store.js'
export function setData(arg) {
runInAction(() => {
store.xx = arg
})
}
我的项目用了 typescript,在非 Page 跟 Component 中引用 store 会导致编译报错
以下是引用方式,大佬能帮忙看下吗
![]()
明显是你没有store.js那个文件啊,或者引用的路径不对,你看看我的demo:
https://github.com/Wyatex/mp-mobx-demo/blob/b7240a45e0d6c1cab49c02a478c043c419576153/src/store/test.ts#L1
https://github.com/Wyatex/mp-mobx-demo/blob/b7240a45e0d6c1cab49c02a478c043c419576153/src/components/component-a/component.ts#L3