摘要:由于小程序不同页面数据,都是通过请求接口返回数据实现的,所以有必要把请求数据的方法作为公共的代码,抽离成为一个单独的 js 文件,独立出来作为一个模块,模块只有通过 module.exports 或者 exports 才能对外暴露接口。var requestUrl = "http://www.wxshop.cn/ind
由于小程序不同页面数据,都是通过请求接口返回数据实现的,所以有必要把请求数据的方法作为公共的代码,抽离成为一个单独的 js 文件,独立出来作为一个模块,模块只有通过 module.exports 或者 exports 才能对外暴露接口。
var requestUrl = "http://www.wxshop.cn/index.php/";
function post(url, data,fun,that) {
if(url == 'undefined'){
return false;
}
var postUrl = requestUrl + url;
wx.request({
url: postUrl,
data: data,
method : "POST",
dataType : "json",
header: {
'content-type': 'application/json' // 默认数据格式
},
success: function (res) {
that[fun](res.data.result);
},
fail : function (res){
console.log('请求失败,哈哈哈');
return {};
}
})
}
module.exports.post = post;
批改老师:韦小宝批改时间:2018-11-21 15:36:22
老师总结:是的!总结的没毛病!不错!继续加油吧......