在main.ts文件中導入vue文件戚扳,顯示找不到"./App.vue"模塊
報錯情況
由于TypeScript只能識別.ts文件么翰,不能識別.vue文件
1.創(chuàng)建xxx.d.ts文件
//shims-vue.d.ts
declare module '*.vue' {
import { ComponentOptions } from 'vue'
const componentOptions: ComponentOptions
export default componentOptions
}
這樣子ts就可以識別vue青灼,把xxx.d.ts文件打開然后關(guān)閉,報錯提示就消失了妓盲。一旦重啟報錯就又出來了聚至,如果覺得麻煩的可以參考第二種方法。
2.使用tsc --init命令
1.安裝node.js
2.全局安裝typescript
npm install -g typescript
tsc -v //查看是否安裝成功本橙,版本號
3.進入文件目錄扳躬,運行tsc --init命令
tsc --init //這是生成一個tsconfig.json文件
把 tsconfig.json 的內(nèi)容改為如下內(nèi)容
{
"compilerOptions": {
"target": "esnext",
"module": "esnext",
"strict": false,
"jsx": "preserve",
"moduleResolution": "node"
}
}