httpRequest.js 994 B

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