html52.com
我爱小程序-开发者交流社区

在微信小程序中使用mobx

在微信小程序中使用mobx

mobx-wxapp

在微信小程序中使用mobxmobx-wxapp简单的提供了一个observer函数,用法如例所示。

用法

案例使用了mobx v4

store:

import {observable} from "../utils/mobx";
const store = observable({
        //observable
        age: 0,
        //computed
        get say() {
            return `i am ${store.age}.`;
        },
        //action
        add() {
            store.age += 1;
        }
    }
);
export default store;

js:

import store from '../stores/store';
import {observer} from "../utils/mobx-wxapp";

Page(observer({store/*,otherStore*/})({
    onLoad() {
    },
    //...
    tapAdd(){
        store.add();
    }
}));

wxml:

<view>age: {{store.age}}</view>
<view>{{store.say}}</view>
<button bindtap="tapAdd">add</button>

License

ISC licensed.

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

真正的个人免签约支付接口

云免签H5支付