React Native mobx 安装
发布时间:2020-12-15 06:30:40 所属栏目:百科 来源:网络整理
导读:1.进入项目目录下,并安装需要的依赖: mobx 和 mobx-react 。 yarn add i mobx mobx-react 我们也要安装一些 babel 插件,以支持 ES7 的 decorator 特性: yarn add babel-plugin-transform-decorators-legacy babel-preset-react-native-stage-0 现在,在.
1.进入项目目录下,并安装需要的依赖:mobx 和mobx-react。 yarn add i mobx mobx-react 我们也要安装一些 babel 插件,以支持 ES7 的 decorator 特性: yarn add babel-plugin-transform-decorators-legacy babel-preset-react-native-stage-0 现在,在.babelrc 文件配置 babel 插件:(如果没有就创建一个) { 'presets': ['react-native'],'plugins': ['transform-decorators-legacy'] }
现在,我们的项目配置好了 2.使用 model 文件中 import {observable,computed,autorun,action,useStrict} from 'mobx'; export default class ETTUserModel extends ETTBaseModel { @observable name:String =''; 3.在观察者文件中 import {observer} from 'mobx-react'; if(DataManager._userModel._isLog == false) { return <LogScene/> } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |