module.exports = (params)=>{
let url = params.url
let method = params.method
let header = params.header || {}
let data = params.data || {}
console.log(data)
if(method){
method = method.toUpperCase()
if(method == 'POST'){
header = {"content-type":"application/json"}
}
}
if(!params.hideLoading){
uni.showLoading({
title:'加载中'
})
}
uni.request({
url:url,
method:method||'GET',
header:header,
data:data||{},
dataType:'json',
sslVerift:false,
success:res=>{
if(res.code&&res.code!=200){
return
}
return typeof params.success =='function' && params.success(res.data)
},
fail:err=>{
return typeof params.fail =='function' && params.fail(err.data)
},
complete:(e)=>{
console.log('请求完成')
uni.hideLoading()
return typeof params.complete =='function' && params.complete(e.data)
}
})
}
在main.js全局挂载
import http from './util/http.js'
Vue.prototype.http=http