Files
ClassContent/历届学生/苏琪/项目练习/newApp/appFont/common/js/http.js
2024-09-27 02:06:13 +08:00

74 lines
1.4 KiB
JavaScript

import config from "./config.js"
class Http {
constructor() {
}
get (params) {
uni.showLoading({
title: '加载中'
});
return new Promise(function(resolve, reject) {
uni.request({
url: `${config.BaseUrl}${params.url}`, //仅为示例,并非真实接口地址。
data: params.data || {},
method: 'GET',
header: params.header || {},
success: (res) => {
uni.hideLoading();
if(res.data.status == 200) {
resolve(res.data.data)
} else {
uni.showToast({
title: res.data.data,
duration: 2000
});
}
},
fail: (error) => {
uni.hideLoading();
uni.showToast({
title: error.message,
duration: 2000
});
}
});
})
}
post (params) {
uni.showLoading({
title: '加载中'
});
return new Promise(function(resolve, reject) {
uni.request({
url: `${config.BaseUrl}${params.url}`, //仅为示例,并非真实接口地址。
data: params.data || {},
method: 'POST',
header: params.header || {},
success: (res) => {
uni.hideLoading();
if(res.data.status == 200) {
resolve(res.data.data)
} else {
resolve(res.data.data)
uni.showToast({
title: res.data.data,
duration: 2000
});
}
},
fail: (error) => {
uni.hideLoading();
uni.showToast({
title: error.message,
duration: 2000
});
}
});
})
}
}
export default new Http()