广告屏react-native项目
Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
 
 
 
 
 

38 righe
840 B

  1. export default class HttpUtil {
  2. /**
  3. * 利用 Promise 的 get 方式请求
  4. * @param url
  5. * @returns {Promise}
  6. */
  7. static get(url) {
  8. return new Promise((resolve, reject) => {
  9. fetch(url)
  10. .then(response => response.json())
  11. .then(result => resolve(result))
  12. })
  13. }
  14. /**
  15. * 利用 Promise 的 post 方式请求
  16. * @param url
  17. * @param params
  18. * @returns {Promise}
  19. */
  20. static post(url, params) {
  21. return new Promise((resolve, reject) => {
  22. fetch(url, {
  23. method: 'POST',
  24. headers: {
  25. 'Accept': 'application/json',
  26. 'Content-Type': 'application/json'
  27. },
  28. body: JSON.stringify(params)
  29. })
  30. .then(response => response.json())
  31. .then(result => resolve(result))
  32. })
  33. }
  34. }