WXHttpRequest.js 1013 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. module.exports = {
  2. getInstance: function() {
  3. return {
  4. _sucCallback: null,
  5. _failCallback: null,
  6. _method: 'GET',
  7. _data: {},
  8. _header: { 'content-type': 'application/json' },
  9. _url: '',
  10. send: function() {
  11. wx.request({
  12. url: this._url,
  13. data: this._data,
  14. method: this._method,
  15. header: this._header,
  16. success: function(res) {
  17. this._sucCallback(res);
  18. }.bind(this),
  19. fail: function(res) {
  20. this._failCallback(res);
  21. }.bind(this)
  22. });
  23. return this;
  24. },
  25. success: function(callback) {
  26. this._sucCallback = callback;
  27. return this;
  28. },
  29. fail: function(callback) {
  30. this._failCallback = callback;
  31. return this;
  32. },
  33. url: function(url) {
  34. this._url = url;
  35. return this;
  36. },
  37. data: function(data) {
  38. this._data = data;
  39. return this;
  40. },
  41. header: function(header) {
  42. this._header = header;
  43. return this;
  44. },
  45. method: function(method) {
  46. this._method = method;
  47. return this;
  48. }
  49. };
  50. }
  51. };