1. 在想要创建项目的目录下输入以下指令,创建vite项目
# npm 6.x
npm init vite@latest <project-name> --template vue
# npm 7+,需要加上额外的双短横线
npm init vite@latest <project-name> -- --template vue
2. 切换到项目目录,安装依赖,运行项目
cd <project-name>
npm install
npm run dev
3. 安装typescrpit
npm install typescript
4. 将main.js文件名称更换为main.ts,且在index.html文件中修改引入main.js文件为main.ts
5. 在main.js同级目录,新建文件shims.d.ts,新建内容如下
declare module '*.vue' {
import { ComponentOptions } from 'vue'
const componentOptions: ComponentOptions
export default componentOptions
}
6. 安装vue-router、element-plus、axios
npm install vue-router@next axios --save
npm install element-plus --save