当前位置:   article > 正文

【vue基础速学】axios - request 拦截器使用、动态增加 token 参数_axios .request 增加请求参数

axios .request 增加请求参数
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>Title</title>
  6. <script src="https://unpkg.com/axios/dist/axios.min.js"></script>
  7. </head>
  8. <body>
  9. <script>
  10. axios.interceptors.request.use(function (config) {
  11. // console.log(config);
  12. config.baseURL = 'http://localhost:9090/jstest';
  13. if (config.params)
  14. config.params.token = "xxxooo";
  15. else
  16. config.params = {token: "xxoo"};
  17. return config;
  18. })
  19. // 此种方式传参时,config 不带 params 属性
  20. axios.get("/news.php?a=1").then(function ({data}) {
  21. data.forEach(function (newsItem) {
  22. })
  23. });
  24. axios.get("/news.php", {
  25. params: {
  26. hot: 1
  27. }
  28. }).then(function ({data}) {
  29. data.forEach(function (newsItem) {
  30. })
  31. })
  32. </script>
  33. </body>
  34. </html>

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/知新_RL/article/detail/715687
推荐阅读
相关标签
  

闽ICP备14008679号