【问题标题】:Vue global variable breaking build with TypeScriptVue 全局变量破坏使用 TypeScript 构建
【发布时间】:2022-01-06 14:05:55
【问题描述】:

我有以下几点:

main.js

Vue.prototype.$someVariable = Vue.observable([] as Array<SomeClass>);

.vue 文件:

console.log(this.$someVariable); //this gets a red squiggly from intellisense

这不会构建,因为:

“ComponentRenderProxy”类型上不存在属性“$someVariable”...

但确实如此,不是吗?有人可以在这里帮助我吗,我错过了什么?如果有帮助,我很乐意提供更多数据,谢谢。

【问题讨论】:

    标签: typescript vue.js visual-studio-code vuejs2


    【解决方案1】:

    在项目根目录添加文件名some-variable.d.ts,内容如下:

    
    import Vue from 'vue'
    
    declare module 'vue/types/vue' {
    
      interface Vue {
        $someVariable: <theType>
      }
    }
    
    

    【讨论】:

    • 我这样做了,但我仍然遇到错误/智能感知问题
    • 请重启编辑器和编译
    猜你喜欢
    • 2017-12-26
    • 1970-01-01
    • 2011-03-31
    • 1970-01-01
    • 2019-02-24
    • 1970-01-01
    • 1970-01-01
    • 2016-01-02
    • 2017-06-02
    相关资源
    最近更新 更多