Can new Promise get the callback of Promise?

export function fetch(url,params={}) {
    return new Promise((resolve , reject) => {
      axios.get(url,{
        params:params
      }).then(response=>{
        resolve(response.data)
      }).catch(err=>{
        reject(err)
      })
    })
}
      

I think everyone else is encapsulated in this way, so can you get the callback after the request by calling the fetch method?

Mar.19,2021

still want .then , axios is to return Promise , if you just want to return data directly, that's fine. (still troublesome)

export function fetch(url,params={}) {
    return axios.get(url,{
        params:params
      })
    .then((response) => Promise.resolve(response.data))
}

chain call, followed by the previous return;
axios has a public configuration. You don't have to write

each.
Menu