TS在vue3中总是报错但是重启vscode后就消失了

问题描述 投票:0回答:1

我按照文档所说创建了一个vue3项目,使用TypeScript和vue-router,但是每次我在

*.vue
foler下创建一个新的
views
文件并将其添加到
src/router/index.ts
中定义的路由时,vscode总是报告错误在
src/router/index.ts
,重启vscode后就消失了

文件“d:/private/frontend/resume-generator/src/views/TestView.vue”未在项目“d:/private/frontend/resume-generator/tsconfig.vitest.json”的文件列表中列出。项目必须列出所有文件或使用“包含”模式。ts(6307)

这是我的文件

//tsconfig.json
{
  "files": [],
  "references": [
    {
      "path": "./tsconfig.node.json"
    },
    {
      "path": "./tsconfig.app.json"
    },
    {
      "path": "./tsconfig.vitest.json"
    }
  ]
}
//tsconfig.node.json
{
  "extends": "@tsconfig/node18/tsconfig.json",
  "include": [
    "vite.config.*",
    "vitest.config.*",
    "cypress.config.*",
    "nightwatch.conf.*",
    "playwright.config.*"
  ],
  "compilerOptions": {
    "composite": true,
    "module": "ESNext",
    "moduleResolution": "Bundler",
    "types": ["node"]
  }
}
//tsconfig.app.json
{
  "extends": "@vue/tsconfig/tsconfig.dom.json",
  "include": ["env.d.ts", "src/**/*", "src/**/*.vue"],
  "exclude": ["src/**/__tests__/*"],
  "compilerOptions": {
    "composite": true,
    "baseUrl": ".",
    "paths": {
      "@/*": ["./src/*"]
    },
    "isolatedModules": true
  }
}
//tsconfig.vitest.json
{
  "extends": "./tsconfig.app.json",
  "exclude": [],
  "compilerOptions": {
    "composite": true,
    "lib": [],
    "types": ["node", "jsdom"]
  }
}

//router/index.ts
import { createRouter, createWebHistory, type RouteRecordRaw } from 'vue-router'
import HomeView from '../views/HomeView.vue'
import RegisterLoginView from '../views/RegisterLoginView.vue'

export const routes: RouteRecordRaw[] = [
  {
    path: '/',
    name: 'home',
    component: HomeView
  },
  {
    path: '/sign',
    name: 'sign',
    component: RegisterLoginView
  },
  {
    path: '/about',
    name: 'about',
    // route level code-splitting
    // this generates a separate chunk (About.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () => import('../views/AboutView.vue')
  },
  {
    path: '/test',
    name: 'test',
    component: () => import('../views/TestView.vue')
  }
]
const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes
})

export default router

我希望它不会再出现了

javascript typescript vuejs3 vue-router
1个回答
0
投票

阅读官方文档并尝试多次后,我发现在 vsode 上使用 oepn 接管模式对此工作空间很有帮助。接管模式

© www.soinside.com 2019 - 2024. All rights reserved.