首页 文章

typescript为Vue库定义添加属性

提问于
浏览
2

我使用包含类型的vue . 但是,我想使用某些插件添加的属性 .

例如

Vue.$ga
Vue.$router

Typescript抱怨Vue没有这些属性 . 我可以以某种方式将这些全局添加到Vue定义中吗?

1 回答

  • 4

    是的你可以:

    import Vue from 'vue'
    
    declare module 'vue/types/vue' {
        interface VueConstructor {
            $ga: any; // define real typings here if you want
            $router: any;
        }
    }
    

    你可以找到更多关于Vue here的信息 .

相关问题