Reactjs 响应时,该函数不加载数据
如何重写函数,以便在每次更改页面时更新和加载该函数。事实上,加载功能只在一个页面上工作,但不会传递给其他页面,如何更改它Reactjs 响应时,该函数不加载数据,reactjs,react-redux,Reactjs,React Redux,如何重写函数,以便在每次更改页面时更新和加载该函数。事实上,加载功能只在一个页面上工作,但不会传递给其他页面,如何更改它 function loadModel(model) { return function(dispatch) { dispatch(moveToPending(model)) const resource = require(`../resources/${model}`) const resourceActions = bindActionCre
function loadModel(model) {
return function(dispatch) {
dispatch(moveToPending(model))
const resource = require(`../resources/${model}`)
const resourceActions = bindActionCreators(resource.actions, dispatch)
const toaster = new Toaster(dispatch)
return new Promise((resolve, reject) => {
resourceActions[getFunctionName(model)]()
.then(res => {
resolve(model)
dispatch(resolveSubscriptions(model))
})
.catch(err => {
if (debug) console.error(err)
reject({ ...err, model })
dispatch(resolveSubscriptions(model))
toaster.error(`Could not load ${model}!`)
})
})
}
}
更新。
这是组件willmount(),我已经有了,需要添加什么
componentWillMount() {
this.props.actions.subscribe(this.subscriptions)
.then(() => {
this.props.actions.fetchRegisters({year: this.state.currentYear, month: defaultMonths()})
.then(() => {
if (!this.props.registers.length) {
this.toaster.warning('There is no data for charts')
}
this.createReportState()
})
})
}
React有一些生命周期方法。为此,您可以使用
componentWillMount
或componentDidMount
。您可以将此函数作为道具传递给其他页面,然后在componentWillMount
中调用它,类似于:
componentWillMount() {
this.props.loadModel(//arg);
}
参考:你如何称呼它
loadModel
?对不起,你可以重新表述这个问题,我真的不明白你想听到什么。你应该避免使用componentWillMount加载数据->参见参考这对我获取页面上的数据没有帮助。