Intellisense不适用于.vue文件

Kok*_*oko 8 intellisense typescript visual-studio-code vetur

我正在使用Visual Studio Code中的Vue和Typescript以及Vetur扩展.问题:当我更新任何代码时,intellisense在.vue文件中工作时无法识别更改.在.ts文件中,intellisense正在工作!

我使用这个定义文件,以便typescript识别.vue文件扩展名:

declare module "*.vue" {
    import Vue from "vue";
    export default Vue;
}
Run Code Online (Sandbox Code Playgroud)

test.ts刚改变了

export default class Test {
    // testFunction() {}    // just removed this
    dummyFunction() {}      // added this
}
Run Code Online (Sandbox Code Playgroud)

app.vue intellisense无效

在任何.vue文件中,intellisense都会建议testFunction并且不识别dummyFunction:

import Test from "./test"
export default class App extends Vue {
    created() {
        const t = new Test()
        t.testFunction()        // allowed - but it doesn't exist
        t.dummyFunction()       // not allowed - but it does exist
    }
}
Run Code Online (Sandbox Code Playgroud)

somefile.ts intellisense正在运行

在常规的旧.ts文件中,intellisense有效.

import Test from "./test"
const t = new Test()
t.testFunction()        // here it works - this is not allowed
t.dummyFunction()       // here it works - this is allowed
Run Code Online (Sandbox Code Playgroud)

如果我关闭VS代码并重新打开,则更新新的更改.这是一个Vetur故障吗?我是否需要更改我的tsconfig或定义文件?

Bra*_*tty 1

我相信你需要在 tsconfig 中添加这样的内容:

\n
{\n  "include": ["src/**/*.vue"]\n}\n
Run Code Online (Sandbox Code Playgroud)\n

来自文档:“如果 glob 模式不包含文件扩展名\xe2\x80\x99t,则仅包含具有受支持扩展名的文件(例如默认情况下为 .ts、.tsx 和 .d.ts,以及 .js 和 . jsx(如果allowJs设置为true)。”

\n

我不确定 Vetur 的表现如何,但从 TS 的角度来看,这应该可以解决问题。

\n