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");
相关推荐
来杯@Java6 小时前
学生选课管理系统(基于springboot+vue前后端分离的项目)计算机毕业设计java
java·spring boot·spring·vue·毕业设计·maven·mybatis
医疗信息化王工14 小时前
医院自律端系统——预警处置模块全栈实战(ASP.NET Core + Vue3 + Quartz 定时调度)
mysql·postgresql·vue·asp.net core·quartz
大大杰哥16 小时前
Vue2学习(1)--了解基本方法与概念
javascript·学习·vue
Agatha方艺璇1 天前
前端开发技术复习笔记
vue·bootstrap·css3·html5·web
小葛要努力2 天前
创建vue2项目
程序人生·vue
七仔啊2 天前
基于海康门禁的人员计数系统
vue
步十人3 天前
【Vue3】前置知识简单概述(包括ES6核心语法,模块化ESM以及npm基础)
arcgis·npm·vue·es6
有梦想的程序星空3 天前
【环境配置】Vue3项目离线化本地部署echarts全攻略
前端·javascript·vue·echarts
向日的葵0064 天前
vue路由(二)
前端·javascript·vue.js·vue
小妖6665 天前
Hydration completed but contains mismatches
javascript·vue·vuepress