标签:nav api 检测 json error let completed 默认 ade
myRequest(Type, url, params, successData, errorData, completeData) { //设置默认数据传数格式 var methonType = "application/json"; var method = Type || ‘GET‘ //判断请求方式 if (method === ‘PUT‘) { var p = Object.keys(params).map(function(key) { return encodeURIComponent(key) + "=" + encodeURIComponent(params[key]); }).join("&"); url += ‘?‘ + p; params = {} } if (method == "POST") { methonType = "application/x-www-form-urlencoded" } var that = this //验证基础库 if (my.request) { //开始正式请求 my.request({ url: that.globalData.api + url, method: method, header: { ‘content-type‘: methonType, }, data: params, //成功回调 success: (res) => { successData(res) }, //错误回调 fail(res) { my.redirectTo({ url: ‘/page/error/error‘ }) //检测是否传参errorData,如果有则执行回调errorData(res) if (errorData) { errorData(res) } }, //检测是否传参completeData,如果有则执行回调completeData(res) complete(res) { my.hideLoading(); my.hideNavigationBarLoading() my.stopPullDownRefresh(); //停止下拉刷新 if (completeData) { completeData(res) } } }) } else { // 如果希望用户在最新版本的客户端上体验您的小程序,可以这样提示 my.alert({ title: ‘提示‘, content: ‘当前支付宝版本过低,无法使用此功能,请升级最新版本支付宝‘ }); } }
标签:nav api 检测 json error let completed 默认 ade
原文地址:https://www.cnblogs.com/zhangYaRan/p/11075740.html