cloud-cross-mobx
v1.0.6
Published
## 安装
Downloads
5
Readme
数云多端mobx
安装
npm i cloud-cross-mobx --save-dev
用法1
- 使用proxy代理形式,加载性能更好
- TIPS: 必须将数值结构出来
pageA.jsx
import { observerModel, observer, toJS } from 'cloud-cross-mobx'
...
const model = observerModel({
test: 1,
arr: [],
setTest2: () => {
model.test = 2
}
})
@observer
class Index extends Component {
...
setTest() {
model.test = 2
toJS(model.arr) // array
}
render() {
const { test } = model
...
<Button onClick={() => {model.setTest()}}></Button>
<View>{test}</View>
}
}
用法2
pageA.jsx
import model from './model.js';
import { observer } from 'cloud-cross-mobx'
...
@observer
class Index extends Component {
...
render() {
...
<Button onClick={() => {model.setTest()}}></Button>
<View>{model.test}</View>
}
}
model.js
import { observerModel, action } from 'cloud-cross-mobx'
@observerModel
class TestModel {
...
test = 1
@action
setTest() {
this.test = 2
}
...
}
export default new TestModel()