主要作用是向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"); }