封装请求
const BASE_URL = 'https://...'
let ajaxTimes = 0;
export const myRequest = (options) => {
ajaxTimes++;
// 显示加载中 效果
uni.showLoading({
title: "加载中",
mask: true,
});
return new Promise((resolve, reject) => {
uni.request({
url: BASE_URL + options.url,
method: options.method || 'GET',
data: options.data || {
},
header: {
'token': uni.getStorageSync('token')
},
success: (res) => {
if (res.data.error_code === 10001) {
uni.showModal({
title:"提示",
content:"身份过期,请重新登录!",
showCancel:false,
success: function(res) {
uni.redirectTo({
url: '/pages/login/login'
});
}
}