我試圖使用axios
發佈來隱藏/顯示模式。我得到的錯誤,無法讀取屬性'隱藏'undefined使用REDD隱藏顯示模式
任何想法?
// dispatch to hide modal
hide() {
this.props.dispatch(hideModal());
}
// dispatch to show modal
show() {
this.props.dispatch(
showError({
type: 'SHOW_MODAL',
modalType: 'SHOW_LOADING',
modalProps: {
onClose: hideModal,
text: 'Please complete all fields',
},
})
);
}
submitForm(UserDetails) {
this.show();
axios
.post('http://localhost:3001/api/users', UserDetails)
.then(function(response) {
this.hide();
})
.catch(function(error) {
console.log(error);
});
}
我不認爲你提出的第二種解決方案會工作,因爲這裏是'axios'' this'導致問題 –
我同意,但我認爲它會引用正確如果你使用箭頭函數,正如我所說,但與正則函數()它不會工作... –