我想在store.subscribe
内调用一个函数,但总是收到错误消息:undefined this
,
这是我正在尝试的代码:
componentDidMount() {
this.GetFilteredData();
}
GetFilteredData = () => {
WithHoldTaxApi.GetFilteredData()
.then((collection) => {
console.log("data", collection)
this.setState({ collection: collection })
}
).catch(error => {
throw error;
})
}
store.subscribe(() => {
console.log(store.getState())
this.GetFilteredData();
})
答案 0 :(得分:0)
我认为您需要执行以下操作:
componentDidMount() {
this.subscribe();
}
GetFilteredData = () => {
WithHoldTaxApi.GetFilteredData()
.then((collection) => {
console.log("data", collection)
this.setState({ collection: collection })
}
).catch(error => {
throw error;
})
}
subscribe = () => {
store.subscribe(() => {
console.log(store.getState())
this.GetFilteredData();
})
}