C端小程序
25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.

http.js 1.4 KiB

6 yıl önce
6 yıl önce
6 yıl önce
6 yıl önce
6 yıl önce
6 yıl önce
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. const postResquest = (url, token, message, postData, doSuccess, doFail) => {
  2. let body={...postData};
  3. if (message != "") {
  4. wx.showLoading({
  5. title: message,
  6. })
  7. }
  8. wx.request({
  9. //项目的真正接口,通过字符串拼接方式实现
  10. url: url,
  11. header: {
  12. "content-type": "application/json;charset=UTF-8",
  13. "token": token
  14. },
  15. data: body,
  16. method: 'POST',
  17. success: function (res) {
  18. //参数值为res.data,直接将返回的数据传入
  19. if (message != "") {
  20. wx.hideLoading()
  21. };
  22. doSuccess(res.data);
  23. },
  24. fail: function (res) {
  25. if (message != "") {
  26. wx.hideLoading()
  27. };
  28. wx.showToast({
  29. title: '网络错误',
  30. })
  31. },
  32. })
  33. }
  34. const getResquest = (url, token, message, getData, doSuccess, doFail) => {
  35. let body = { ...getData };
  36. if (message != "") {
  37. wx.showLoading({
  38. title: message,
  39. })
  40. }
  41. wx.request({
  42. url: url,
  43. header: {
  44. "content-type": "application/json;charset=UTF-8",
  45. "token": token
  46. },
  47. data: body,
  48. method: 'GET',
  49. success: function (res) {
  50. if (message != "") {
  51. wx.hideLoading()
  52. };
  53. doSuccess(res.data);
  54. },
  55. fail: function (res) {
  56. if (message != "") {
  57. wx.hideLoading()
  58. };
  59. wx.showToast({
  60. title: '网络错误',
  61. })
  62. },
  63. })
  64. }
  65. module.exports = {
  66. postResquest: postResquest,
  67. getResquest: getResquest
  68. }