http.js 668 B

12345678910111213141516171819202122232425262728293031
  1. import { baseURL } from "./base.js";
  2. // console.log(window.localStorage.getItem("token"));
  3. let token;
  4. uni.getStorage({
  5. key: "token",
  6. success: function (res) {
  7. console.log(res);
  8. token = res.data;
  9. },
  10. });
  11. console.log(token);
  12. export const request = (option) => {
  13. return new Promise((resolve, reject) => {
  14. uni.request({
  15. url: baseURL + option.url,
  16. method: option.method,
  17. data: option.data,
  18. headers: {
  19. "content-type": "application/json",
  20. Authorization: "Bearer " + "token",
  21. },
  22. success: (res) => {
  23. resolve(res);
  24. },
  25. fail: (error) => {
  26. reject(error);
  27. },
  28. });
  29. });
  30. };