vue3学习进阶一
创建一个 Vue 应用
已安装 18.0 或更高版本的 Node.js
npm create vue@latest
✔ Project name: …
✔ Add TypeScript? … No / Yes
✔ Add JSX Support? … No / Yes
✔ Add Vue Router for Single Page Application development? … No / Yes
✔ Add Pinia for state management? … No / Yes
✔ Add Vitest for Unit testing? … No / Yes
✔ Add an End-to-End Testing Solution? … No / Cypress / Playwright
✔ Add ESLint for code quality? … No / Yes
✔ Add Prettier for code formatting? … No / Yes
Scaffolding project in ./…
Done.
cd ‘project-name’
npm install
npm run dev
启动项目后 报错问题处理
main.ts中引入App.vue报错,提示“Cannot find module ‘./App.vue’
- 报错原因是:vite使用的是ts,ts不识别 .vue 后缀的文件
- 解决问题处理:src目录下会有一个 “vite-env.d.ts” 文件或者是env.d.ts,找到该文件,在里面添加一下代码:
declare module “*.vue” {
import { DefineComponent } from “vue”
const component: DefineComponent<{}, {}, any>
export default component
}
注意:源文件内容为:/// < reference types=“vite/client” /> 此条内容不变 原样保留即可