From 92786d47f33ab0f4913d0b8f1a5ba4494191f903 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E9=99=88=E9=9B=AF=E9=92=B0?= <1622345892@qq.com>
Date: Wed, 3 May 2023 20:58:09 +0800
Subject: [PATCH] =?UTF-8?q?=E7=AC=94=E8=AE=B0?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
...46\344\271\240\347\254\224\350\256\260.md" | 111 +++++++++++
...46\344\271\240\347\254\224\350\256\260.md" | 160 +++++++++++++++
...46\344\271\240\347\254\224\350\256\260.md" | 34 ++++
...46\344\271\240\347\254\224\350\256\260.md" | 184 ++++++++++++++++++
...46\344\271\240\347\254\224\350\256\260.md" | 30 +++
5 files changed, 519 insertions(+)
create mode 100644 "24\351\231\210\351\233\257\351\222\260/230423-Vue\345\255\246\344\271\240\347\254\224\350\256\260.md"
create mode 100644 "24\351\231\210\351\233\257\351\222\260/230424-Vue\345\255\246\344\271\240\347\254\224\350\256\260.md"
create mode 100644 "24\351\231\210\351\233\257\351\222\260/230425-Vue\345\255\246\344\271\240\347\254\224\350\256\260.md"
create mode 100644 "24\351\231\210\351\233\257\351\222\260/230427-Vue\345\255\246\344\271\240\347\254\224\350\256\260.md"
create mode 100644 "24\351\231\210\351\233\257\351\222\260/230428-Vue\345\255\246\344\271\240\347\254\224\350\256\260.md"
diff --git "a/24\351\231\210\351\233\257\351\222\260/230423-Vue\345\255\246\344\271\240\347\254\224\350\256\260.md" "b/24\351\231\210\351\233\257\351\222\260/230423-Vue\345\255\246\344\271\240\347\254\224\350\256\260.md"
new file mode 100644
index 0000000..6519079
--- /dev/null
+++ "b/24\351\231\210\351\233\257\351\222\260/230423-Vue\345\255\246\344\271\240\347\254\224\350\256\260.md"
@@ -0,0 +1,111 @@
+# 路由入门
+
+#
+## 一.安装 vue-router
+
+### npm
+```
+ npm install vue-router
+```
+
+### yarn
+```
+ yarn add vue-router
+```
+
+#
+## 二.创建路由的配置文件:JavaScript
+```js
+//1.引用路由组件
+import Home from './components/Home.vue'
+import About from './components/About.vue'
+import Student from './components/Student.vue'
+
+//2.定义路由
+//每个路由都映射一个组件
+const routes=[
+ {path:'/',component:Home},
+ {path:'/about',component:About},
+ {path:'/student',component:Student}
+]
+
+//3.创建路由实例并传递 `routes` 配置
+//createRouter():需要引入
+const router=createRouter({
+
+ //4.提供 history 模式
+ // history:createWebHashHistory(),//路由会带#号
+ history:createWebHistory(),//使用时路由不带#号,但是会有点小问题,后面解决
+
+ routes//`routes:routes` 的缩写
+})
+
+
+//5.创建并挂载实例
+
+// createApp(App).use(router).mount('#app')
+
+const app=createApp(App)
+
+//让整个项目都支持路由
+app.use(router)
+app.mount('#app')
+```
+
+#
+## 三.RouterLink 和 RouterView
+
+### RouterLink : 入口
+
++ RouterLink 实现路由之间的跳转
+
++ RouterLink 对应 html 中的a 标签,但是与a 标签不同的是,跳转的时候并**不会刷新页面**
+
++ RouterLink映射的结果为其对应组件的整个页面内容
+
+```html
+
+ 前往
+
+ 返回
+```
+
+### RouterView : 出口
+
++ RouterView 根据路由显示对应的组件,当你的路由path 与访问的地址相符时,会将指定的组件替换
+
++ RouterView 相当于RouterLink的承载页面,用于展示RouterLink 的的内容
+
+```html
+
+```
+
+#
+## 四.显示页面有按钮
+
++ 在 App.vue 中导入首页
+```vue
+
+
+
+
+
+```
+
+#
+## 五.显示页面无按钮存在
+
++ 在 App.vue 中设置出口 RouterView
+```vue
+
+
+
+
+
+
+
+```
\ No newline at end of file
diff --git "a/24\351\231\210\351\233\257\351\222\260/230424-Vue\345\255\246\344\271\240\347\254\224\350\256\260.md" "b/24\351\231\210\351\233\257\351\222\260/230424-Vue\345\255\246\344\271\240\347\254\224\350\256\260.md"
new file mode 100644
index 0000000..ef0e5ff
--- /dev/null
+++ "b/24\351\231\210\351\233\257\351\222\260/230424-Vue\345\255\246\344\271\240\347\254\224\350\256\260.md"
@@ -0,0 +1,160 @@
+# 动态路由匹配
+#
+## 一.设置路由的匹配
+
++ 进入路由配置文件,在定义的路由中添加相关的路径信息
+
+### 带参路由的动态匹配
+
++ 路径参数 用**冒号 :** 表示。当一个路由被匹配时,它的 params 的值将在每个组件中以 **this.$route.params** 的形式暴露出来。
+
++ **component** 获取要跳转页面的位置
+
+```js
+//2.定义路由
+const routes = [
+ { path: '/student/:id', component: StudentId },
+]
+```
+
+### 错误路由的匹配
+
++ 在括号之间使用了自定义正则表达式,并将 **pathMatch** 参数标记为可选可重复。
+
++ 在 to 中输入 **/:pathMatch(.*)** 匹配错误的路径信息
+
++ + **component** 获取要跳转页面的位置
+
+```js
+//2.定义路由
+const routes = [
+ //将匹配不到的报错页面,跳转为此页面
+ { path: '/:pathMatch(.*)', component: NotFound }
+]
+```
+
+#
+## 二.获取路由信息
+
++ **vue2**路由是通过this.$route和this.$router来控制的
+
++ **vue3**的路由中
+
+ + **useRoute** 相当于以前的 **this.$route**,
+
+ + **useRouter** 相当于 **this.$router**
+
+### $route
+
++ **route** 是一个跳转的路由对象,每一个路由都会有一个route对象
+
++ **route** 是一个**局部的对象**,可以获取对应的name,path,params,query等
+
+ + **$route.path** :获取当前路由对象的路径,会被解析为绝对路径,如 “/index/” 。
+
+ + **$route.params** :获取包含路由中的动态片段和全匹配片段的键值对
+
+ + **$route.query** :获取 **? 号传参**包含路由中查询参数的键值对。例如,对于 /index?id=1 ,会得到 $route.query.id == 1。
+```js
+ { path: '/student/:id', component: StudentId },
+```
+```html
+
这里是id为{{ $route.params.id}} 的页面
+```
+
+
+### userRoute
+
++ 相当于 $route
+
++ **push方法** 是useRouter()才有的, 用**useRoute()实例化**的对象是没这方法的
+```js
+//实例化
+const route=userRoute()
+```
+
+### $router
+
++ **router** 是VueRouter的一个对象,通过Vue.use(VueRouter)和VueRouter构造函数得到一个router的实例对象
+
++ **router** 是一个**全局的对象**,包含了所有的路由包含了许多关键的对象和属性。例如history对象
+
+ + **$router.push({path:’/path’})** : 本质是向history栈中添加一个路由,在我们看来是 切换路由,但本质是在添加一个history记录
+
+ + **$router.replace({path:’/path’})** : 替换路由,没有历史记录
+
+### userRouter
+
++ 相当于 $router
+
++ 通过useRouter来手动控制路由变化
+
++ push方法是useRouter()才有的
+
+```js
+//实例化
+const router=userRouter()
+```
+
+#
+## 三.响应路由变化 :watch
+
++ 使用 **watch 侦听器** 获取路由的变化
+
+### 选项式中
+```vue
+
+```
+
+### 组合式
+```vue
+
+```
\ No newline at end of file
diff --git "a/24\351\231\210\351\233\257\351\222\260/230425-Vue\345\255\246\344\271\240\347\254\224\350\256\260.md" "b/24\351\231\210\351\233\257\351\222\260/230425-Vue\345\255\246\344\271\240\347\254\224\350\256\260.md"
new file mode 100644
index 0000000..e2c53c7
--- /dev/null
+++ "b/24\351\231\210\351\233\257\351\222\260/230425-Vue\345\255\246\344\271\240\347\254\224\350\256\260.md"
@@ -0,0 +1,34 @@
+# 嵌套路由:children
+
+#
+## 使用方式
+
++ 在自己的路由配置文件里面创建对应的路由
+
++ 子路由需要在 父路由 对应的参数中使用 **children** 配置;
+
++ 切记,在children 中,子路由的路径不要加 / ;
+```js
+
+//定义路由
+const routes=[
+ {path:'/',component:Home},
+ {
+ path:'/about',
+ component:About,
+ //嵌套路由
+ children:[
+ {
+ //当 /about/:id 是匹配成功
+ //(\\d+)自能为数字
+ path:':id(\\d+)',
+ // AboutId 将被渲染到 About 的 RouterView 内部
+ component:AboutId
+ }
+ ]
+ },
+ {path:'/student',component:Student},
+ {path:'/student/:id(\\d+)',component:StudentId},
+ {path:'/:pathMatch*',component:NotFund}
+]
+```
\ No newline at end of file
diff --git "a/24\351\231\210\351\233\257\351\222\260/230427-Vue\345\255\246\344\271\240\347\254\224\350\256\260.md" "b/24\351\231\210\351\233\257\351\222\260/230427-Vue\345\255\246\344\271\240\347\254\224\350\256\260.md"
new file mode 100644
index 0000000..907d490
--- /dev/null
+++ "b/24\351\231\210\351\233\257\351\222\260/230427-Vue\345\255\246\344\271\240\347\254\224\350\256\260.md"
@@ -0,0 +1,184 @@
+# 编程式导航和components 命名视图
+
+#
+## 一.编程式导航
+
++ 编程式导航就是以编写代码的形式,实现 RouterLink 创建 a 标签定义导航链接的作用
+
+#
+### 导航到指定的url
+
++ 选项式的使用
+
+ + 使用 **this.$router.push** 方法实现导航到指定的url
+
+ + **this.$router.push** 方法会向 history 栈添加一个新的记录,当点击浏览器后退按钮时,会回到之前的 URL。
+
+```vue
+
+```
+
++ 组合式的使用
+
+ + 导入 **useRouter** 方法,并实例化
+
+ + 使用 **router.push** 方法实现导航到指定的url
+```vue
+
+```
+
++ 一些方法的使用
+
+ + 在 **{}** ,使用 **path** 时, **params** 会被忽略
+
+ + **params** 可以与 name (命名的路由)一起使用
+```js
+// 字符串路径
+router.push('/users/eduardo')
+
+// 带有路径的对象
+router.push({ path: '/users/eduardo' })
+
+// 命名的路由,并加上参数,让路由建立 url
+router.push({ name: 'user', params: { username: 'eduardo' } })
+
+// 带查询参数,结果是 /register?plan=private
+router.push({ path: '/register', query: { plan: 'private' } })
+
+// 带 hash,结果是 /about#team
+router.push({ path: '/about', hash: '#team' })
+
+```
+
+#
+### 不添加历史记录: router.replace({})
+
+```
+ 1. 作用与 router.push 类似,唯一的不同是, router.push 在导航时会向 history 添加新的历史记录,而 router.replace 不会
+
+ 2. router.push 转换为 router.replace 的方法是: 添加一个 replace:true 属性
+```
+```js
+ router.push({ path: '/home', replace: true })
+ // 相当于
+ router.replace({ path: '/home' })
+
+```
+
+#
+### 横跨历史记录 :router.go
+
++ router.go(n) 方法采用一个整数作为参数,表示在历史堆栈中前进或后退多少步
+```js
+// 向前移动一条记录,与 router.forward() 相同
+router.go(1)
+
+// 返回一条记录,与 router.back() 相同
+router.go(-1)
+
+// 前进 3 条记录
+router.go(3)
+
+// 如果没有那么多记录,静默失败
+router.go(-100)
+router.go(100)
+```
+
+#
+## components 命名视图
+
++ 一个视图使用一个组件渲染,对于同个路由,多个视图就需要多个组件。为了保证各组件的正确使用,在配置路由时,使用了 **components)** 配置(比原来多了个s)
+
+#
+### 单命名视图
+```js
+const router = createRouter({
+ history: createWebHashHistory(),
+ routes: [
+ {
+ path: '/',
+ components: {
+ default: Home,
+ // UserId: UserId 的缩写
+ UserId,
+ // 它们与 `` 上的 `name` 属性匹配
+ About,
+ },
+ },
+ ],
+})
+```
+
+#
+### 嵌套命名路由
+
++ 在 children 中 使用 components 配置
+```html
+
+ 这是主页
+
+
+
+
+
+
+
+
+
+
+```
+```js
+const routes = [
+ {
+ path: '/',
+ component: Home,
+ children: [
+ {
+ path:'/emails',
+ component:Emails
+ },{
+ path:'/user',
+ components:{
+ default:User,
+ //相当于 UserId :UserId
+ UserId,
+ //与 RouterView 的name 对应
+ About
+ }
+ }
+ ]
+ }, {
+ path: '/:pathWatch(.*)*',
+ component: NotFund
+ }
+]
+```
\ No newline at end of file
diff --git "a/24\351\231\210\351\233\257\351\222\260/230428-Vue\345\255\246\344\271\240\347\254\224\350\256\260.md" "b/24\351\231\210\351\233\257\351\222\260/230428-Vue\345\255\246\344\271\240\347\254\224\350\256\260.md"
new file mode 100644
index 0000000..3ebea67
--- /dev/null
+++ "b/24\351\231\210\351\233\257\351\222\260/230428-Vue\345\255\246\344\271\240\347\254\224\350\256\260.md"
@@ -0,0 +1,30 @@
+# element-plus 的使用
+
+#
+## 一.安装 element-plus 包管理器
+```js
+// yarn
+ yarn add element-plus
+
+// npm
+ npm install element-plus --save
+
+// pnpm
+ pnpm install element-plus
+```
+
+#
+## 二.全局引入配置
+
++ 在 main.js 文件中配置
+```js
+//导入 element-pius 和相关文件
+import ElementPlus from 'element-plus'
+import 'element-plus/dist/index.css'
+
+const app=createApp(app)
+//全局配置
+app.use(ElementPlus)
+
+app.mount('#app')
+```
\ No newline at end of file
--
Gitee