所以我创建了一个组件,它使用我提供的 props 发送 post 请求。
尽管我熟悉 Async await 我出于某种原因似乎无法让它返回已履行的承诺的实际值,而只是挂起。
我尝试使用更多功能进行包装,因为我知道承诺没有得到解决。
我觉得我错过了一些东西。
下面是我的代码示例
export default class PostController extends React.Component {
constructor(props) {
super(props)
}
Wrapper = (body) => {
try{
let x = this.Send(body);
return x;
console.log(x)
}catch(e){console.log(e)}
}
Send = async (body) => {
try{
let data = await this.Post(body);
return data;
}catch(e){console.warn(e)}
}
Post = async (body) => {
try{
const options = {
method: 'POST',
uri: 'XXXXXXXXXXXXXXXXXXXX',
body: body
}
const data = await rp(options);
return data;
}catch(e){console.warn(e)} …Run Code Online (Sandbox Code Playgroud)