uniapp-网络请求
api.jsconstbaseUrl = "http://192.168.0.80:8080"// GET请求let listing = function(urling,data,header){let token = uni.getStorageSync('token')if(token){header={"token":token}}return new Promise((resolve,re
·
api.js
const baseUrl = "http://192.168.0.80:8080"
// GET请求
let listing = function(urling,data,header){
let token = uni.getStorageSync('token')
if(token){
header={
"token":token
}
}
return new Promise((resolve,reject)=>{
uni.request({
url:baseUrl+urling,
method:'GET',
header,
data
})
.then((res)=>{
if(res[1].data.ErrCode==401){
uni.clearStorage();
alert("登录超时请重新登录")
}else{
resolve(res[1])
}
})
.catch((err)=>{
reject(err)
})
})
}
// POST请求
let publicing = function(urling,data,header,headerlist){
let token = uni.getStorageSync('token')
if(token){
header ={
"token":token
}
}
return new Promise((resolve,reject)=>{
uni.request({
url:baseUrl+urling,
method:'POST',
data:data,
header
})
.then((res)=>{
if(res[1].data.ErrCode==401){
uni.clearStorageSync();
alert("登录超时请重新登录")
}else{
resolve(res[1])
}
})
.catch((err)=>{
reject(err)
})
})
}
export{listing,publicing}
更多推荐
已为社区贡献3条内容
所有评论(0)