export default {
//封装uni.request():
request(options) {
return new Promise((resolve, reject) => {
//书写异步操作的代码
uni.request({
...options,
success: res => {
// console.log('***********',res)
if (options.native) {
resolve(res) //调取接口后返回的原生数据
}
if (res.statusCode === 200) {
resolve(res.data) //异步操作执行成功
} else {
console.log('请求的接口没有找到');
reject(res) //异步操作执行失败
}
}
})
})
},
get(url, data = {}, options = {}) {
//#ifdef H5
options.url = '/wk'+url;
//#endif
//#ifdef APP-PLUS || MP-WEIXIN
options.url = 'http://wskk.momayun.cn'+url;
//#endif
options.url = url;
options.data = data;
options.method = 'get';
options.header = {
'Content-Type': 'application/json'
}
return this.request(options)
},
post(url, data = {}, options = {}) {
//#ifdef H5
options.url = '/wk'+url;
//#endif
//#ifdef APP-PLUS || MP-WEIXIN
options.url = 'http://wskk.momayun.cn'+url;
//#endif
options.data = data;
options.method = 'post';
options.header = {
'Content-Type': 'application/x-www-form-urlencoded'
}
return this.request(options)
}
}
封装uni.request
最新推荐文章于 2024-09-30 15:57:59 发布