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

在nuxt框架中,客户端使用出现问题 #91

Closed LuDongWei closed 6 years ago

LuDongWei commented 6 years ago

代码:

const Fly = require('flyio/dist/npm/fly')

let fly = new Fly()

fly.interceptors.request.use(function (request) {
    return request
})

fly.interceptors.response.use(
    (response) => {
        let res = response.data

        return res
    }, (err) => {
        console.log('err:', err)
    }
)

export default fly

报错:

{ ReferenceError: XMLHttpRequest is not defined
    at new Fly (/Users/ludongwei/project/Unclutter Files/work/nuxt-test/node_modules/flyio/dist/npm/fly.js:176:33)
    at Object.84 (core/http.js:4:0)
    at __webpack_require__ (webpack:/webpack/bootstrap 2c92f4a5df9d5ced7bac:25:0)
    at Object.83 (core/user.js:1:0)
    at __webpack_require__ (webpack:/webpack/bootstrap 2c92f4a5df9d5ced7bac:25:0)
    at Object.82 (core/index.js:1:0)
    at __webpack_require__ (webpack:/webpack/bootstrap 2c92f4a5df9d5ced7bac:25:0)
    at Object.65 (pages/user/login.vue?0686:1:0)
    at __webpack_require__ (webpack:/webpack/bootstrap 2c92f4a5df9d5ced7bac:25:0)
    at Object.57 (pages/user/login.vue:1:0)
    at __webpack_require__ (webpack:/webpack/bootstrap 2c92f4a5df9d5ced7bac:25:0)
    at <anonymous> statusCode: 500, name: 'ReferenceError' }

是不是fly还不支持nuxt的关系呢,其实我想来应该也是没问题的

LuDongWei commented 6 years ago

直接 const Fly = require('flyio')
这样也是不行的 报错 Fly is not a constructor

wendux commented 6 years ago

看你报错信息,fly执行环境不是浏览器,要不怎么会没有xmlhttprequest, 可以检查一下你的代码。

LuDongWei commented 6 years ago

我换了 axios 以后就没问题了。。。。

wendux commented 6 years ago

这...,先关了, 以后有复现再打开