Vite+Typescript+Vue3学习笔记

Vite+Typescript+Vue3学习笔记

1、项目搭建

1.1、创建项目(yarn)

shell 复制代码
D:\WebstromProject>yarn create vite
yarn create v1.22.19
[1/4] Resolving packages...
[2/4] Fetching packages...
[3/4] Linking dependencies...
[4/4] Building fresh packages...

success Installed "create-vite@4.4.1" with binaries:
      - create-vite
      - cva
√ Project name: ... vite-project
√ Select a framework: >> Vue
√ Select a variant: >> TypeScript

Scaffolding project in D:\WebstromProject\vite-project...

Done. Now run:

  cd vite-project
  yarn
  yarn dev

Done in 14.81s.

1.2、vite-env.d.ts

vite使用的是ts,不识别.vue后缀的文件,需在vite-env.d.ts配置下

tsx 复制代码
/// <reference types="vite/client" />
declare module "*.vue" {
    import { DefineComponent } from "vue"
    const component: DefineComponent<{}, {}, any>
    export default component
}

1.3、常用依赖

1、@types/node

ts需安装node的类型,否则使用node相关会提示找不到

shell 复制代码
# @types/node
yarn add -D @types/node

2、auto-import

用于简化Vue3中ref、reactive**、**watch和UI组件的导入

shell 复制代码
# unplugin-vue-components、unplugin-auto-import
yarn add -D unplugin-vue-components unplugin-auto-import

3、sass

shell 复制代码
# sass
yarn add -D sass

4、vue-router

shell 复制代码
# vue-router
yarn add vue-router@4
相关推荐
renhongxia123 分钟前
多模态融合驱动下的具身学习机制研究
运维·学习·机器人·自动化·知识图谱
今儿敲了吗30 分钟前
46| FBI树
数据结构·c++·笔记·学习·算法
疯狂成瘾者32 分钟前
git学习目录
git·学习
jinanwuhuaguo1 小时前
AI工具终极解构:OpenClaw、Coze、Dify、FastGPT、n8n、LangChain、RagFlow、GPTBots.ai 的万言深度剖析
人工智能·学习·重构·新人首发·openclaw
苦瓜小生1 小时前
【黑马点评学习笔记 | 实战篇 】| 6-Redis消息队列
redis·笔记·后端
紫_龙1 小时前
最新版vue3+TypeScript开发入门到实战教程之DOM操作
javascript·vue.js·typescript
sheeta19982 小时前
LeetCode 每日一题笔记 日期:2025.03.19 题目:3212.统计X和Y频数相等的子矩阵数量
笔记·leetcode·矩阵
observe1012 小时前
51单片机学习
嵌入式硬件·学习·51单片机
leaves falling3 小时前
数据结构-堆学习
java·数据结构·学习
峥嵘life3 小时前
Android16 EDLA【CTS】CtsConnectivityMultiDevicesTestCases存在fail项
android·学习