asyncfunctiongetList(){returnawaitaxios({method:'post',url:'/list/tododata/',data:json}).then(res=>{returnaxios.get('/list/tododata',{params:{'page':newState.current,}}).then((res)=>{constdata=res.data;returndata.results//想获取这个东西}).catch((error)=>{console.log(error);});}).catch((err)=>{console.log(err);});}getList().then(value=>{newState.list=value})returnnewStateasync返回的还是一个Promise,获取Promise的值还是异步的,以至于最后return的newSate还是没有被更新,请问想要获取最新的newState该怎么改?
2 回答
温温酱
TA贡献1752条经验 获得超4个赞
asyncfunctiongetList(){awaitaxios({method:'post',url:'/list/tododata/',data:json}).catch((error)=>{console.log(error);});constresults=awaitaxios.get('/list/tododata',{params:{'page':newState.current,}}).then((res)=>{constdata=res.data;returndata.results;}).catch((error)=>{console.log(error);});returnresults;}
吃鸡游戏
TA贡献1829条经验 获得超7个赞
functionpostTododata(){returnnewPromise((resolve,reject)=>{axios({method:'post',url:'/list/tododata/',data:json}).then(res=>{resolve(res.data);})})}functiongetTododata(){returnnewPromise((resolve,reject)=>{axios({method:'get',url:'/list/tododata/',params:{'page':newState.current,}}).then(res=>{resolve(res.data);})})}asyncfunctiongetList(){awaitpostTododata();newState.list=awaitgetTododata();}getList();
添加回答
举报
0/150
提交
取消