我被交给一个基地来开发一个项目 . 它是在Vue和Typescript中制作的,在网上没有太多支持 .

我目前需要进行多次API调用以检查服务的可用性,并且必须在组件内部执行这些调用 . 出于某种原因,我无法弄清楚如何做到这一点 .

我现在拥有的是:

import * as Vue from 'vue';
import { Component } from 'vue-property-decorator';
import Axios, { AxiosInstance, AxiosRequestConfig, AxiosError, AxiosResponse, AxiosStatic } from 'axios';

@Component({
(...)  
})

export class Something extends Vue {
    public $http: Axios;
constructor() {
    super();
    this.$http = Axios.create({
        baseURL: "https://swapi.co/api/people/1/"
    });
}

testFunc() {
    let data: any;
    this.$http.get("https://swapi.co/api/people/1/", data)
       .then((res: AxiosResponse) => {
        console.log(res.data);
     })
      .catch((ex: any) => {
        console.log(ex);
      });
 }


}

为了让这个工作起作用,我已经改变了几件事,因此我粘贴的代码更像是一个结构而不是其他任何东西 . 我在视图中也有一个按钮,调用testFunc() . 此外,Axios不会被识别为类型,即使我导入“axios”,它也不起作用 . AxiosInstasnce确实有效,但让我无处可去 .