let app = getApp()
export function request(config) {
my.showLoading({
content: '加载中...'
});
let host = app.globalData.host;
// console.log('host',host)
// 解构赋值
let {
url = '',
data = '',
method = 'POST',
} = { ...config }
// console.log('data',data)
return new Promise((resolve, reject) => {
my.request({
url: host + url,
headers:headers,
method: method,
data: {...data} ,
success: (res) => {
//这里面判断如果接口返给的不是200
resolve(res.data)
},
fail: (err) => {
reject(err)
},
complete: () => {
setTimeout(()=> {
my.hideLoading();
}, 400)
}
});
})
}
app.js文件里面 定义上全局的 基地址
?globalData: {
? ? host: '基地址'
? },