代码之家  ›  专栏  ›  技术社区  ›  metamemelord

Vue资源+Typescript:类型“VueConstructor<Vue>上不存在属性“http”

  •  0
  • metamemelord  · 技术社区  · 7 年前

    我正在一个使用Vue资源的Vue项目中使用Typescript。这个项目运行得很好,但是我遇到了一个typescript编译器错误。

    enter image description here enter image description here

    this.$http

    我查过了 this this ,和 this

    [编辑]解决方法(另附我的答案):

    vue-resource/types/vue.d.ts

    对任何示例使用泛型和类型转换Vue <any>Vue.http . 但是,这可能会导致tslint警告,因此我使用 (Vue as any) 然后进入 (Vue as any).http

    0 回复  |  直到 7 年前
        1
  •  1
  •   metamemelord    7 年前

    this 链接。你可以通读,这里有个解决方法:

    对任何示例使用泛型和类型转换Vue <any>Vue.http . 但是,这可能会导致tslint警告,因此我使用 (Vue as any) (Vue as any).http

        2
  •  0
  •   Wahib Kerkeni    6 年前

    我认为您需要添加一个名为“http.d.ts”的新定义文件主.ts位于以下位置:

    import Vue from 'vue';
    
    declare module 'vue/types/vue' {
      interface VueConstructor {
        http: any;
      }
    }
    

    推荐文章