Vue3+elementPlus+Vite项目

Vue3+elementPlus+Vite项目

  • [1. 项目创建](#1. 项目创建)
    • [1.1. 使用pnpm创建项目](#1.1. 使用pnpm创建项目)
    • [1.2. 启动项目](#1.2. 启动项目)
    • [1.3. 配置项目`url`映射](#1.3. 配置项目url映射)
    • [1.4. 安装依赖包](#1.4. 安装依赖包)
  • [2. vue3路由](#2. vue3路由)
    • [2.1. 添加路由配置文件](#2.1. 添加路由配置文件)
    • [2.2. 注册路由](#2.2. 注册路由)
  • [3. 注册elemet-plus](#3. 注册elemet-plus)
  • [4. Pinia](#4. Pinia)

1. 项目创建

1.1. 使用pnpm创建项目

shell 复制代码
> pnpm create vite --template=vue-ts
◇  Project name:
│  gcs # 输入项目名称

# 是否使用 npm 进行安装并立即启动
◆  Install with npm and start now?
│  ○ Yes / ● No
└

1.2. 启动项目

shell 复制代码
> cd gcs 
> pnpm install
> pnpm dev

1.3. 配置项目url映射

json 复制代码
// 修改tsconfig.app.json
{
    // ...
    "compilerOptions": {
				// ...
        "baseUrl": ".",          // 添加跟路径 .
        "paths": {							// url映射
            "@/*": ["src/*"]
        }
    },
	// ...
}

// 修改vite.config.ts
export default defineConfig({
    // ...
    resolve: {
        alias: {
            "@": path.resolve(__dirname, "src"),
        },
    },
    // ...
});

1.4. 安装依赖包

shell 复制代码
> pnpm install element-plus
> pnpm install @element-plus/icons-vue
> pnpm install vue-router

2. vue3路由

2.1. 添加路由配置文件

添加router目录,并在该目录项添加index.ts

路径:../src/route/index.ts

ts 复制代码
/*
../srt/route/index.ts
*/  
import { createRouter, createWebHistory } from "vue-router";

const routes = [
    {
        path: "/",
        name: "user_info",
        component: import("../sys/UserInfo.vue"),
    },
];

const router = createRouter({
    history: createWebHistory(),
    routes,
});

export default router;

2.2. 注册路由

ts 复制代码
/*
../srt/main.ts
*/
import { createApp } from 'vue'
import App from './App.vue'
import router from './router'

const app = createApp(App)
app.use(router) // 注册路由
app.mount('#app')

3. 注册elemet-plus

ts 复制代码
/*
../srt/main.ts
*/
import { createApp } from 'vue'
import App from './App.vue'
import router from './router'
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'

const app = createApp(App)
app.use(router) // 注册路由
app.mount('#app')
app.use(ElementPlus)  // 注册elemet-plus

4. Pinia

shell 复制代码
pnpm i pinia

注册Pinia

ts 复制代码
/*
../srt/main.ts
*/
import { createApp } from "vue";
import "./style.css";
import App from "./App.vue";
import { createPinia } from 'pinia'

const app = createApp(App);
const pinia = createPinia()
app.use(pinia);
app.mount("#app");
相关推荐
ttwuai12 小时前
XYGo Admin 菜单与路由:Vue3 动态路由 + GoFrame 权限菜单的完整实现方案
前端·vue·后台框架
ttwuai16 小时前
XYGo Admin 国际化实战:Vue3 中后台多语言方案详解
前端·javascript·vue.js·vue
还得是你大哥2 天前
Java互联网医院管理系统源码SpringBoot
java·spring boot·vue
会周易的程序员2 天前
aiDgeScanner:工业设备扫描与管理的一体化利器——深度解析上位机与扫描端的无缝协作
c++·物联网·typescript·electron·vue·iot·aiot
阿部多瑞 ABU3 天前
运动会智能编排系统 - 完整详细需求规格说明书
python·贪心算法·vue·html
AIGC包拥它3 天前
RAG 项目实战进阶:基于 FastAPI + Vue3 前后端架构全面重构 LangChain 0.3 集成 Milvus 2.5 构建大模型智能应用
人工智能·python·重构·vue·fastapi·milvus·ai-native
次次皮5 天前
代理启动前端dist包
java·前端·vue
展示猪肝5 天前
Vue2 + FastAPI + Dify 实现 AI 医疗预检分诊助手:从问诊追问到医生审核闭环
人工智能·vue·fastapi·dify
何忆清风6 天前
Easy Agent Pilot - Rust实现的开源桌面Agent软件
ai·rust·vue·agent·tauri·开发工具
码界筑梦坊6 天前
361-基于Python的空气质量气候数据分析预测系统
python·信息可视化·数据分析·flask·vue·毕业设计