微信小程序开发post方法与get方法的封装
第一步:在utils文件夹下创建httpUtil.js文件
第二步:创建函数httpPost方法代码如下:
function Post(url, data, cb, isShow, showNetError, that, showLoading) { if (showLoading == true || showLoading == undefined){ wx.showNavigationBarLoading(); wx.showLoading({ title: '加载中...', }) } var basicData = { vloginPwd: api.vloginPwd, vtoken: api.vtoken } if (!isEmpty(data)) { for (var key in data) { try { basicData[key] = data[key]; } catch (e) { } } } wx.request({ url: url, header: { 'content-type': 'application/x-www-form-urlencoded' }, method: 'POST', data: basicData, success: (res) => { if (res.data.state == 200) { typeof cb == "function" && cb(res.data, ""); } else { if (isShow == true) { wx.showModal({ title: '提示', content: res.data.msg, showCancel: false }) } } }, fail: (err) => { if (showNetError) { that.setData({ errorDisplay:'', containHidden:true }) } }, complete: (res) => { setTimeout(function () { wx.hideNavigationBarLoading(); wx.hideLoading(); }, 100) } }); };
第三步,在module里添加:
module.exports = { httpGet: Get, httpPost: Post };
第四步,引入
var httpUtil = require('../../utils/HttpHelper.js')
第五步,如何使用
onload:function(option){ var that = this; httpUtil.httpPost(api.getListUrl, jsonData, function (res) { wx.showModal({ title: '提示', content: res.msg, showCancel: false, confirmText:"查看", success: function (res) { console.log("res.data===", res.data); if (res.confirm) { that.toDetail(res.data); } } }) }, true, true, this); }
如有疑问请留言或者到本站社区交流讨论,感谢阅读,希望通过本文能帮助到大家,谢谢大家对本站的支持!
华山资源网 Design By www.eoogi.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
华山资源网 Design By www.eoogi.com
暂无评论...
更新日志
2024年09月23日
2024年09月23日
- 国风大师纯音系列《古筝仙子 常静演奏 十指弹一》1CD[FLAC][919MB]
- DasKapital-OneMustHaveChaosInsidetoGiveBirthtoaDancingStar(2024)[24-44.1]WAV
- 王菲.1999-《只爱陌生人》日本东芝版[低速原抓WAV+CUE]
- 张小英1987-金奖金曲第一集[新加坡版][WAV+CUE]
- 鹿晗.2015-重启【海蝶】【FLAC分轨】
- 张芸京.2012-小女孩【金牌大风】【WAV+CUE】
- 余天.2002-雄狮魅力金曲2CD(南方金点系列)【南方】【WAV+CUE】
- 银霞.1982-《结·SAYYESMYBOY》台湾复刻版[WAV+CUE]
- 梁汉文1993-火热动感[引进版][WAV+CUE]
- 梁汉文2008-EDMONDHITS48[香港]3CD[WAV+CUE]
- 国风大师纯音系列《童丽-[渭城曲]》1CD[WAV分轨][593.5MB]
- 国风大师纯音系列《许菱子《烧筝2》古筝曲集》1CD[WAV分轨][1.3GB]
- 王子异《1996 Part.2》[320K/MP3][18.29MB]
- 群星.1994-宝丽金最倾情3CD【宝丽金】【WAV+CUE】
- 乐俊亨.2024-同泪【CharioticMusic】【FLAC分轨】