【发布时间】:2020-08-01 04:56:04
【问题描述】:
async saveForm(data) {
return await axios({
method: "post",
url: FORM_PORTAL_CONTROLLER_URL + 'savemoratorium',
body: JSON.stringify(data)
}).then(res =>
this.setState({ refNo: res.data.reference }))
}
我无法设置我从请求中获得的设置状态,它给了我以下错误。 Post 请求完美执行。我想捕获响应并更改 state.function 在组件内。以下错误出现在页面的控制台中,之后我得到一个白页。
react_devtools_backend.js:6 TypeError: Cannot read property 'length' of undefined react-dom.production.min.js:152 Uncaught (in promise) TypeError: Cannot read property 'length' of undefined
【问题讨论】:
-
在axios请求中将
body替换为data
标签: html reactjs async-await axios