diff --git "a/\345\220\264\344\275\263\345\256\207/20250519_vue\350\267\257\347\224\261\347\232\204\351\207\215\345\256\232\345\220\221.md" "b/\345\220\264\344\275\263\345\256\207/20250519_vue\350\267\257\347\224\261\347\232\204\351\207\215\345\256\232\345\220\221.md" new file mode 100644 index 0000000000000000000000000000000000000000..a377a5ae274d1501c054da7db5b78eb9e3b3dfc8 --- /dev/null +++ "b/\345\220\264\344\275\263\345\256\207/20250519_vue\350\267\257\347\224\261\347\232\204\351\207\215\345\256\232\345\220\221.md" @@ -0,0 +1,12 @@ +# Vue路由的重定向 + +```js +const router = createRouter({ + history: createWebHistory(import.meta.env.BASE_URL), + routes: [ + {path: '/', redirect: 'login'}, //当访问/时会重定向到/login + {path:'/login',name:'login',meta:{title: '登录界面'},component:()=> import('路径')}, + {path:'/:pathMatch(.*)',redirect:'/404'}, + ], +}); +``` \ No newline at end of file diff --git "a/\345\220\264\344\275\263\345\256\207/20250520_\351\233\206\346\210\220ui\345\272\223.md" "b/\345\220\264\344\275\263\345\256\207/20250520_\351\233\206\346\210\220ui\345\272\223.md" new file mode 100644 index 0000000000000000000000000000000000000000..6e6aba69bf352e80b742d07a94647c5dc3f9f88c --- /dev/null +++ "b/\345\220\264\344\275\263\345\256\207/20250520_\351\233\206\346\210\220ui\345\272\223.md" @@ -0,0 +1,123 @@ +# Vue3集成ElementPlus组件库 + +## 在Vue3项目中集成Element Plus的步骤如下: + +### 1. 安装Element Plus + +在项目目录下运行以下命令安装Element Plus: + +```bash +npm install element-plus +``` + +如果需要使用图标组件,还需要安装图标依赖: + +```bash +npm install @element-plus/icons-vue +``` + +### 2. 引入Element Plus + +在项目的入口文件(如`main.js`)中引入Element Plus: + +```js +import { createApp } from 'vue'; +import App from './App.vue'; +import ElementPlus from 'element-plus'; +import 'element-plus/dist/index.css'; + +const app = createApp(App); +app.use(ElementPlus); +app.mount('#app'); +``` + + + +### 3. 配置语言包(可选) + +如果需要使用中文语言包,可以在`main.js`中添加以下代码: + +```js +import zhCn from 'element-plus/es/locale/lang/zh-cn'; + +app.use(ElementPlus, { + locale: zhCn, +}); +``` + + + +### 4. 使用图标组件 + +在`main.js`中注册所有图标组件: + +```js +import * as ElementPlusIconsVue from '@element-plus/icons-vue'; + +for (const [key, component] of Object.entries(ElementPlusIconsVue)) { + app.component(key, component); +} +``` + +### 5. 按需导入(可选) + +为了优化性能,可以使用按需导入工具,例如`unplugin-vue-components`和`unplugin-auto-import`: + +```bash +npm install -D unplugin-vue-components unplugin-auto-import +``` + +在`vite.config.js`中配置: + +```js +import { defineConfig } from 'vite'; +import vue from '@vitejs/plugin-vue'; +import AutoImport from 'unplugin-auto-import/vite'; +import Components from 'unplugin-vue-components/vite'; +import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'; + +export default defineConfig({ + plugins: [ + vue(), + AutoImport({ + resolvers: [ElementPlusResolver()], + }), + Components({ + resolvers: [ElementPlusResolver()], + }), + ], +}); +``` + +### 6. 自定义主题(可选) + +创建一个SCSS文件(如`element-variables.scss`): + +```scss +@forward "element-plus/theme-chalk/src/common/var.scss" with ( + $colors: ( + "primary": ( + "base": #1890ff, + ), + ), + $border-radius: ( + "base": 4px, + ) +); +``` + +在`vite.config.js`中配置: + +```js +export default defineConfig({ + css: { + preprocessorOptions: { + scss: { + additionalData: `@use "@/styles/element-variables.scss" as *;`, + }, + }, + }, +}); +``` + +通过以上步骤,您已经成功在Vue3项目中集成了Element Plus,并可以开始使用其丰富的UI组件。 \ No newline at end of file diff --git "a/\345\220\264\344\275\263\345\256\207/20250521_ pinia.md" "b/\345\220\264\344\275\263\345\256\207/20250521_ pinia.md" new file mode 100644 index 0000000000000000000000000000000000000000..7f56aa223dbbbaf592d31c2debf54c8a655719d5 --- /dev/null +++ "b/\345\220\264\344\275\263\345\256\207/20250521_ pinia.md" @@ -0,0 +1,110 @@ +# Vue3使用 Pinia + +## Pinia 是一个用于 Vue.js 的状态管理库,它是 Vuex 的继任者,由 Vue.js 团队成员之一的 [Eduardo San Martin Morote](https://github.com/pixelart) 开发。Pinia 的目标是提供一个更简单、更直观且更灵活的状态管理解决方案,同时保持与 Vue 3 的紧密集成。 + +### Pinia 的特点 + +1. **简单易用** + - Pinia 的 API 设计简洁直观,易于上手。它减少了 Vuex 中一些复杂的概念,如 `mutations` 和 `actions` 的严格区分,使得状态管理更加直观。 +2. **与 Vue 3 紧密集成** + - Pinia 专为 Vue 3 设计,充分利用了 Vue 3 的 Composition API 和 `setup` 函数。它与 Vue 3 的响应式系统无缝集成,使得状态管理更加自然。 +3. **模块化和可扩展性** + - Pinia 支持将状态拆分成多个模块(store),每个模块可以独立管理自己的状态、计算属性和操作方法。这使得大型项目的状态管理更加清晰和可维护。 +4. **类型安全** + - Pinia 提供了良好的 TypeScript 支持,使得状态管理更加类型安全。你可以通过 TypeScript 的类型系统来定义状态的结构,减少运行时错误。 +5. **插件支持** + - Pinia 支持插件系统,你可以通过插件来扩展 Pinia 的功能,例如添加持久化存储、日志记录等。 + +### Pinia 与 Vuex 的比较 + +| 特性 | Pinia | Vuex | +| :------------------ | :-------------------------- | :-------------------------------------------------------- | +| **复杂性** | 简单直观 | 相对复杂,有严格的概念区分(mutations、actions、getters) | +| **与 Vue 3 的集成** | 专为 Vue 3 设计,无缝集成 | 需要适配 Vue 3 的响应式系统 | +| **模块化** | 支持模块化,每个 store 独立 | 支持模块化,但配置相对复杂 | +| **类型安全** | 提供良好的 TypeScript 支持 | 提供 TypeScript 支持,但配置相对复杂 | +| **插件系统** | 支持插件系统 | 支持插件系统 | +| **学习曲线** | 学习曲线平缓,易于上手 | 学习曲线较陡,需要理解多个概念 | + +### 使用场景 + +Pinia 适用于各种规模的 Vue 项目,无论是小型项目还是大型复杂项目。它特别适合以下场景: + +1. **小型项目**:Pinia 的简洁性使得它非常适合小型项目,可以快速搭建状态管理。 +2. **大型项目**:通过模块化设计,Pinia 可以将状态拆分成多个独立的 store,使得大型项目的状态管理更加清晰和可维护。 +3. **需要类型安全的项目**:如果你使用 TypeScript 开发 Vue 项目,Pinia 提供了良好的类型支持,可以减少运行时错误。 + +### 示例代码 + +以下是一个简单的 Pinia 示例,展示如何在 Vue 3 项目中使用 Pinia: + +#### 安装 Pinia + +```bash +yarn add pinia +``` + +#### 设置 Pinia + +在 `main.js`文件中: + +```js +import { createApp } from 'vue' +import App from './App.vue' +import { createPinia } from 'pinia' + +const app = createApp(App) +const pinia = createPinia() + +app.use(pinia) +app.mount('#app') +``` + +#### 创建 Store + +在 `src/stores/` 文件夹中创建一个 `useCounterStore.js` 文件: + +```js +import { defineStore } from 'pinia' + +export const useCounterStore = defineStore('counter', { + state: () => ({ + count: 0 + }), + actions: { + increment() { + this.count++ + }, + decrement() { + this.count-- + } + } +}) +``` + +#### 在组件中使用 Store + +创建一个简单的组件 `Counter.vue`: + +```vue + + + +``` + +### 总结 + +Pinia 是一个现代化的状态管理库,专为 Vue 3 设计,提供了简单、直观且类型安全的 API。它适用于各种规模的项目,无论是小型项目还是大型复杂项目。通过 Pinia,你可以更轻松地管理应用的状态,提高开发效率和代码可维护性。 + diff --git "a/\345\220\264\344\275\263\345\256\207/20250523_\344\273\212\346\227\245\350\200\203\350\257\225\346\227\240\347\254\224\350\256\260.md" "b/\345\220\264\344\275\263\345\256\207/20250523_\344\273\212\346\227\245\350\200\203\350\257\225\346\227\240\347\254\224\350\256\260.md" new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391