const BASE_URL="http://119.23.232.49:8080"
const request=(option)=>{
if(!option.hideLoading){
uni.showLoading({
title:'数据加载中'
})
}
return new Promise((resolve, reject)=>{
uni.request({
url:BASE_URL+option.url,
data:option.data ||{},
method:option.method || 'get',
})
.then((response) => {
uni.hideLoading()
let [error, res] = response;
if(res){
resolve(res.data);
}
else{
uni.showToast({
title:res.data.msg,
icon:'error'
})
}
}).catch(error => {
uni.showToast({
title:'系统错误',
icon:'error'
})
let [err, res] = error;
reject(error)
})
})
}
export default request
uniapp的请求封装
最新推荐文章于 2024-05-30 21:45:00 发布