wendux / fly

:rocket: Supporting request forwarding and Promise based HTTP client for all JavaScript runtimes.
https://wendux.github.io/dist/#/language
MIT License
3.9k stars 639 forks source link

mpvue 中await 有问题 #61

Closed kala888 closed 6 years ago

kala888 commented 6 years ago
 "flyio": "^0.5.5",
    "lodash": "^4.17.10",
    "mpvue": "^1.0.10",
    "vuex": "^2.3.1",
    "wx-promise-pro": "^2.3.1"

在backend.js中通过await方式调用request方法,在request中返回了对象(如日志所示,有数据),可是在backend.js中取到的是空 image

kala888 commented 6 years ago

解决了,好像,fly.request返回的promise有问题?包了一层promise,就对了 问题代码

export default function request(options) {
  const { uri, data, method = 'get', ...others } = options
    fly.request(uri, data, {
      method,
      ...others,
  })
}

修改后

export default function request(options) {
  const { uri, data, method = 'get', ...others } = options
    return new Promise((resolve, reject) => { 
      fly.request(uri, data, {
        method,
        ...others,
     }).then(resolve).catch(reject)
  })
}
wendux commented 6 years ago

fly返回的promise应该是没有问题的,你开始的代码中要return 一下。

wendux commented 6 years ago

先关了,有问题再打开