axios_talent.js 907 B

12345678910111213141516171819202122232425262728
  1. const axios_instance = axios.create({
  2. baseURL: baseUrl + "talent",
  3. timeout: 30000,
  4. headers: {'X-Requested-With':'XMLHttpRequest'},
  5. withCredentials: true,
  6. });
  7. async function postJson(url,data,error) {
  8. return new Promise((resolve, reject) => {
  9. axios_instance.post(url, JSON.stringify(data), {
  10. headers: { 'Content-Type': 'application/json;charset=UTF-8' }
  11. }).then((result) => {
  12. const data = result.data;
  13. if (data.code === 1) {
  14. if (typeof error === 'function') {
  15. error(data);
  16. return false;
  17. } else {
  18. vant.showToast(data.msg);
  19. return false;
  20. }
  21. } else if (data.code === 401) {
  22. location.href = '/talent/login/login';
  23. }
  24. return resolve(data);
  25. });
  26. });
  27. }