axios 几个 .then 承诺 - 如何组合它们?

axios couple of `.then` promises - how to combine them?

假设我有一个 axios 函数的包装器 - 应该在每个 ajax 查询上实现的东西,所以我想保持代码干燥。像那样:

import axios     from "axios"
import NProgress from "nprogress"

const query = (url, options) => {
  NProgress.start()

  return axios({
    url: url,
    method: options.method || "GET",
    data: options.data || {}
  }).then(() => {
    NProgress.done()
  })
}

export default query

问题是,如果我将 .then 解析器添加到 query(),什么也没有发生!像那样:

从“./query.js”导入查询

query("something", {}).then(() => { console.log("This will never logged") })

如何将另一个 .then() 添加到 query() 函数?

只是 return 东西!

const query = (url, options) => {
  NProgress.start()

  return axios({
    url: url,
    method: options.method || "GET",
    data: options.data || {}
  }).then((response) => {
    NProgress.done()
    return response // change is here
  })
}