request.js 609 B

12345678910111213141516171819
  1. const { baseUrl } = require('./env').prod
  2. module.exports = {
  3. request : function(url, type , data = {}){
  4. let fullUrl = `${baseUrl}${url}`
  5. let token = wx.getStorageSync('token') ? wx.getStorageSync('token') : ''
  6. return new Promise((resolve,reject)=>{
  7. wx.request({url: fullUrl,method:type,data,header: {'content-type': 'application/json','Authorization': token},
  8. success(res){resolve(res)},
  9. fail(){
  10. wx.showToast({
  11. title: '接口请求错误',
  12. icon:'none'
  13. })
  14. reject('接口请求错误')
  15. }
  16. })
  17. })
  18. },
  19. }