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");
相关推荐
溪语流沙7 小时前
Django + Vue电商项目第001讲:开篇|注册登录加增删改查,那不是电商
redis·python·mysql·docker·typescript·django·vue
程序员阿黄7 小时前
基于 Django 与 Vue 3 的智能实验室预约系统设计与实现
后端·python·mysql·django·vue·毕设
.Hypocritical.8 小时前
Vue CLI(vue-cli)和 Vite 超详细对比
vue
志尊宝1 天前
Vue3 零基础每日笔记(040):Vite 创建 Vue3 + TS 项目——企业标配从这一篇开始
笔记·vue·html·前端开发·软件开发
凤城老人1 天前
从零手写开源私有云盘|Flask+Vue3+Electron全栈网盘,单容器一键部署
python·docker·electron·vue
球球不吃虾1 天前
Nuxt在使用过程中的一些小总结(二)
前端·vue·nuxt
志尊宝2 天前
Vue3 零基础每日笔记(038):亲手封装 useDebounceFn 与 useThrottleFn——高频事件的流量阀
前端·javascript·vue·html·vue3
愛芳芳2 天前
基于 Electron + Vue3 的仿 PC 微信客户端项目实战
前端·javascript·css·elementui·typescript·electron·vue
梦想的颜色2 天前
【AI科普】AI 时代,纯 H5+CSS PK React & Vue:前端技术孰优孰劣深入剖析
ai·前端框架·大模型·vue·react·html5·vibecoding
志尊宝2 天前
Vue3 零基础每日笔记(043):defineModel 与 defineExpose 的 TS 用法——3.4+ 新 API 进阶
前端·javascript·vue·html·vue3