摘要:总结:1,公共util.js文件,模块化,代码可以重复使用2,返回值module.exports,通过module.exports才能对位暴露接口3,wx.request请求网络4,wx.showToast显示消息提示框5,wx.hideToast隐藏消息提示框/******************* util.js *********************
总结:1,公共util.js文件,模块化,代码可以重复使用
2,返回值module.exports,通过module.exports才能对位暴露接口
3,wx.request请求网络
4,wx.showToast显示消息提示框
5,wx.hideToast隐藏消息提示框
/******************* util.js ***********************/
var requestUrl = "http://www.admin.com/index.php/";
function post(url, data, fun,t) {
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);
console.log(res.data.result)
},
fail: function (res) {
console.log('请求失败,请重试');
return {};
}
})
}
module.exports.post = post
批改老师:韦小宝批改时间:2018-12-25 11:53:23
老师总结:写的很不错!现在正是小程序普及的时候!自己也可以写个自己的小程序玩玩!也是很不错的!