//这是H5的配置
"h5" : {
"title" : "掌上研学",
"devServer" : {
"https" : true,
"port" : 443
},
"router" : {
"mode" : "hash",
"base" : "/h5/"
},
"domain" : "m.yanxuelbb.com"
}
请求部分的代码,是简单封装的
// == 测试线
// const bannerUrl = 'http://test.yanxuelbb.com/'
// const ApiUrl = 'http://test.yanxuelbb.com/api';
const isInit = false;
export const ajax = (opt) => {
let userInfo = uni.getStorageSync('userInfo')
let token = userInfo.token
let uid = userInfo.uid
// console.log(uid)
opt.data.token = token
opt.data.uid = uid
opt = opt || {};
opt.url = opt.url || '';
opt.data = opt.data || null;
opt.method = opt.method || 'POST';
opt.header = opt.header || {
"Content-Type": "application/x-www-form-urlencoded"
};
opt.success = opt.success || function() {};
//console.log(ApiUrl)
// 获取当前网络状态
uni.getNetworkType({
success: function (res) {
// console.log(res.networkType) //网络状态
if(res.networkType=='none'){
uni.showToast({
title: '网络异常',
icon: 'none'
});
}else{
uni.showLoading({
title:'加载中...'
})
uni.request({
url: ApiUrl + opt.url,
data: opt.data,
method: opt.method,
header: opt.header,
dataType: 'json',
success: res =>{
uni.hideLoading()
if(res.data.code==1 || res.data.code == 2){
opt.success(res.data);
} else if(res.data.code == 999) {
console.log(res);
uni.showModal({
content: res.data.msg,
cancel: false,
success:data => {
if(data.confirm) {
uni.reLaunch({
url: '/pages/user/login.vue'
})
}
}
})
} else if(res.data.code != 3) {
if(res.data.msg) {
uni.showToast({
title: res.data.msg,
icon: 'none'
})
} else {
console.log(opt.url);
console.log(res);
}
}
},
fail: function(res) {
uni.showToast({
title: "网络异常",
mask: false,
duration: 1500,
icon:'none'
});
}
})
}
}
});
}
s***@qq.com (作者)
在编辑器中预览是空白页,运行到谷歌浏览器是可以的,360浏览器不发请求,分享到微信内置浏览器打开时:安卓内可以打开发请求,苹果不发请求
2019-08-09 11:35
s***@qq.com (作者)
编辑器版本号:2.1.0.20190713
2019-08-09 11:39
DCloud_UNI_GSQ
回复 s***@qq.com: 请求部分代码贴一下
2019-08-09 12:56
s***@qq.com (作者)
回复 DCloud_UNI_GSQ: 我重新编辑了一下问题,你看一下上边
2019-08-09 14:05
s***@qq.com (作者)
回复 s***@qq.com: 回复 DCloud_UNI_GSQ: APP端的数据请求是完全没有问题的
2019-08-09 14:07
DCloud_UNI_GSQ
回复 s***@qq.com: 能否提供复现问题的简单示例
2019-08-09 18:07
s***@qq.com (作者)
回复 DCloud_UNI_GSQ: 这个不知道如何提供示例,是整个项目打的包
2019-08-10 20:39