国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 熱點 > 微信 > 正文

微信小程序中post方法與get方法的封裝

2024-07-22 01:17:21
字體:
來源:轉載
供稿:網友

微信小程序開發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);}

如有疑問請留言或者到本站社區交流討論,感謝閱讀,希望通過本文能幫助到大家,謝謝大家對本站的支持!

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 德兴市| 绵竹市| 马鞍山市| 云梦县| 民乐县| 廊坊市| 九龙坡区| 青河县| 衡南县| 大丰市| 星座| 丽江市| 阜康市| 卓资县| 五河县| 潞西市| 黔江区| 南昌市| 重庆市| 台前县| 乃东县| 射阳县| 苍梧县| 靖宇县| 怀安县| 锡林郭勒盟| 遂溪县| 桂平市| 景泰县| 郁南县| 南丹县| 什邡市| 崇州市| 宁国市| 怀集县| 卫辉市| 渭南市| 平武县| 连江县| 玉山县| 渑池县|