interview-answe icon indicating copy to clipboard operation
interview-answe copied to clipboard

206.[vue]封装成Promise

Open webVueBlog opened this issue 5 years ago • 1 comments

[vue]

webVueBlog avatar Apr 21 '20 10:04 webVueBlog

const http = (options) => {
 return new Promise((resolve, reject) => {
  uni.showLoading({
   title: '加载中...',
   mask: true,
  })
 uni.request({
  method: options.method,
  url: option.url,
  data: options.data,
  header: {
 
  },
  success:(res)=>{
   resolve(res.data)
  },
  fail: (err) => {
   reject(err.data)
   let code = err.data.code;
   switch(code) {
    case 100:
     break;
   }
  },
 complete: ()=> {
  uni.hideLoading();
 }
 }
}

export default http

webVueBlog avatar Apr 21 '20 10:04 webVueBlog