const BASE_url = 'http://192.18.1.50:8201'
export const myRequest = (options)=>{ //options 为传入的对象
return new Promise((resolve,reject)=>{
uni.request({
url: BASE_url + options.url,
method: options.method || 'GET',
data: options.data || {},
header:{Authorization:'Bearer ' + uni.getStorageSync('token')},
success: (res)=>{
// console.log(res.data);
resolve(res.data)
},
fail: (err)=>{
// console.log(err);
uni.showToast({
title: 'network error!' ,
icon:"error",
duration:1000
})
reject(err)
}
})
})
}
在其他 post 调用
async change(e) {
let {index} = e.detail ;
const res = await this.$myRequest({
url: '/xxxx-portal/deviceRemote/operating',
method: "POST",
data: {
deviceCode: this.deviceCode,
instructName: "operating-six-grid-device",
data: {
'DLV': index,
'UID':uni.getStorageSync("memberId") ,
}
}
});
console.log(res);
if (res.code == 200) {
uni.showToast({
title: `第${index+1}个关卡开始了`,
icon: 'none'
})
} else {
uni.showToast({
title: res.data.message,
icon: 'none'
})
}
// uni.showToast({
// title: `点击第${index+1}个宫格`,
// icon: 'none'
// })
},
在其他地方get 调用
async getpersoninfo(){
const res = await this.$myRequest({
url:'/xxx-portal/sso/info' ,
})
if(res){
uni.setStorageSync("memberId",res.data.id)
}
},