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");
相关推荐
钛态18 小时前
前端微前端架构:大项目的救命稻草还是自找麻烦?
前端·vue·react·web
钛态18 小时前
前端趋势:别被时代抛弃
前端·vue·react·web
恶猫1 天前
网页自动化模拟操作时,模拟真实按键触发事件【终级方案】
前端·javascript·自动化·vue·网页模拟
无心使然云中漫步1 天前
Openlayers调用ArcGis地图服务之五 —— 要素识别(/identify)
前端·arcgis·vue·数据可视化
蜡台1 天前
H5入住浙里办App详细步骤
vue·uniapp·h5·浙政钉
呱牛do it2 天前
企业级门户网站设计与实现:基于SpringBoot + Vue3的全栈解决方案(Day 7)
java·vue
呱牛do it5 天前
企业级门户网站设计与实现:基于SpringBoot + Vue3的全栈解决方案(Day 5)
java·vue
无心使然云中漫步5 天前
Openlayers调用ArcGis地图服务之一 —— 地图切片(/tile)
前端·arcgis·vue·数据可视化
Python私教5 天前
我在开发 ShadcnVueAdmin 时发现了一个 Claude Code 超级插件
vue
无心使然云中漫步5 天前
Openlayers调用ArcGis地图服务之三 —— 要素查询(/query)
前端·arcgis·vue·数据可视化