我在Visual Studio Code中使用Vue和Typescript,以及Vetur扩展程序。问题是:当我更新任何代码时,在.vue文件中工作时,智能感知无法识别更改。但在.ts文件中,智能感知是有效的! 我使用这个定义文件使typescript认识.vue文件扩展名:
declare module "*.vue" {
import Vue from "vue";
export default Vue;
}
例子
test.ts刚刚被修改了
export default class Test {
// testFunction() {} // just removed this
dummyFunction() {} // added this
}
app.vue智能提示无法工作
在任何.vue
文件中,智能提示始终建议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
}
}
somefile.ts 的代码提示功能正在工作
在普通的 .ts 文件中,代码提示功能是有效的。
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
如果我关闭 VS Code 并重新打开,那么新的更改就会被更新。这是 Vetur 的故障吗?我需要修改我的 tsconfig 或定义文件吗?
.ts
文件和types.d.ts
文件中的更改!我在 Vetur 的 Github 上发布了一个问题,但由于某种原因,他们将其标记为已解决... - Kokodoko