【问题标题】:Why Axios causes InterceptorManager error?为什么 Axios 会导致 InterceptorManager 错误?
【发布时间】:2020-08-18 14:46:02
【问题描述】:

下一个代码 const axios = require("axios"); 在 Typescript 类中引发错误消息:

InterceptorManager.js:44 未捕获类型错误:无法分配给对象“#”的只读属性“forEach” 在 eval (InterceptorManager.js:44) 在 Object../node_modules/axios/lib/core/InterceptorManager.js (:468:1) 在 webpack_require (:20:30) 在 eval (Axios.js:5) 在 Object../node_modules/axios/lib/core/Axios.js (:456:1) 在 webpack_require (:20:30) 在 eval (axios.js:5) 在 Object../node_modules/axios/lib/axios.js (:408:1) 在 webpack_require (:20:30) 在 eval (index.js:1)

我有 0.19.2 的 Axios。

什么会导致这个错误?

【问题讨论】:

    标签: javascript typescript axios


    【解决方案1】:

    我试试这个,效果很好 从'@angular/core'导入{组件,OnInit}; 从“axios”导入axios;

    @Component({
      selector: 'app-test-comp',
      templateUrl: './test-comp.component.html',
      styleUrls: ['./test-comp.component.css']
    })
    export class TestCompComponent implements OnInit {
    
      constructor() { }
    
      ngOnInit() {
      }
    
      testCall(){
        axios.get("https://jsonplaceholder.typicode.com/posts").then((res) => {
          console.log(res);
        });
      }
    
    }
    
    HTML CODE 
    <button (click)="testCall()">Call http</button>
    

    【讨论】:

    • 我也试过这种方式,但同样的错误......和“import * as axios from "axios"”也是
    【解决方案2】:

    找到了解决方案。它位于捆绑包中的“使用严格”模式。 解决问题后,导入工作正常。

    【讨论】:

      猜你喜欢
      • 2018-11-08
      • 2023-02-22
      • 2012-05-04
      • 2020-07-16
      • 2014-06-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多