为了账号安全,请及时绑定邮箱和手机立即绑定

es6函数的.then中无法return结果

es6函数的.then中无法return结果

德玛西亚99 2019-03-01 20:33:23
export function postMethod(data) {  const baseURL = process.env.BASE_API   axios({     method: 'post',     url: baseURL + '/img_upload',     timeout: 50000,     data: data,     headers: {      'loginToken': getLoginToken()     }   }).then(res => {    const respose = res.data    if (respose.errno == 'success') {  //成功       //console.log(respose.data)       //******************此处返回((((((((((((((((       return respose.data      //******************此处返回))))))))))))))))     } else if (respose.errno == 'fail') {  //失败       Message({         message: respose.msg,        type: 'error',         duration: 2 * 1000       })     } else { //登录失败       Message({         message: '登录失败',        type: 'error',         duration: 2 * 1000       })     }   }) }在别处使用postMethod(data)时,结果是undefined。这个return没起作用,如何让函数返回调取接口时返回的数据?
查看完整描述

2 回答

?
繁星coding

TA贡献1797条经验 获得超4个赞

return axios....

postMethod(data).then(resposeData=>{
    ...
})


查看完整回答
反对 回复 2019-03-01
?
一只萌萌小番薯

TA贡献1795条经验 获得超7个赞

export function postMethod(data) {  const baseURL = process.env.BASE_API  return axios(...)


查看完整回答
反对 回复 2019-03-01
  • 2 回答
  • 0 关注
  • 2529 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号