VUE, can you tell us why there is another promise? on the outside of this axios?

The response.data returned by

axios can be used, but why is there another layer of promise? on the outside? Isn"t it more troublesome to write like this when using
? The question I encountered yesterday just saw a person ask the same question, but that person didn"t post the code. I posted the code. Can you explain why you did it? Thank you

get().then(data => {
   console.log(data)
})
  
export function get (url, data = {}) {
  return new Promise((resolve, reject) => {
    axios.get(url, {params: data})
      .then(response => {
        resolve(response.data)
      }, err => {
        reject(err)
      })
  })
}
Feb.01,2022

package a layer Promise there is absolutely no need for superfluous action

  

can increase the burden of js engine gc and reserve optimization space for asking Party A for money in the future.
also adds redundant code, which can reduce the readability of the code and increase the difficulty of maintenance, making it easy for companies not to fire themselves.

Menu