博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
react+mobx 编写 withStoreHistory 装饰器
阅读量:6922 次
发布时间:2019-06-27

本文共 826 字,大约阅读时间需要 2 分钟。

主要作用是向store里面注入一个history对象,方便story里面的函数调用

function withStoreHistory(storeName) {  if (!storeName) return console.error(`必须输入一个查询数据的store`);  return function(Target) {    class WithStoreHistory extends Component {      componentDidMount() {        const { history } = this.props;        const store = this.props[storeName];        store.history = history;      }      render() {        return 
; } } return WithStoreHistory; };}

使用

需要在inject调用后才能获取到store的数据,所以写在inject下面

const MERCHANTSTORE = "merchantStore";@inject(MERCHANTSTORE)@withStoreHistory(MERCHANTSTORE)@observerclass BusinessEntrance extends Component {  render() {    return (      
...
); }}

函数中使用

@action.bound  handleSettingData() {    this.history.push("/merchants_settled");  }

转载于:https://www.cnblogs.com/ajanuw/p/10090243.html

你可能感兴趣的文章
Android解析XML文件
查看>>
Spring AOP前置通知和后置通知
查看>>
Windows 之间用rsync同步数据(cwRsyncServer配置)
查看>>
android gps定位
查看>>
JFinal AOP学习笔记
查看>>
idea 查看Java类字节码 自定义工具的使用
查看>>
“效果系列一”:jQuery 手风琴效果
查看>>
java相对路径获取(读取)文件
查看>>
VS上写helloworld
查看>>
反射机制——获取Class对象的三种方式
查看>>
react-native 初始化指定版本
查看>>
怎样看服务器负载状况好坏
查看>>
NSCopying
查看>>
总结&终结帖:博客迁移到poos.github.io
查看>>
使用 Postman 与 Kotlin 交互REST API接口数据
查看>>
OCMock学习笔记
查看>>
解决win7/win8 winsxs目录不断变大的问题
查看>>
windows 20008DHCP中继
查看>>
docker 容器网络篇
查看>>
DAY 19
查看>>