一、路由的基本概念

你是否好奇单页应用(SPA)是如何在不刷新页面的情况下实现页面切换的?这就离不开路由的功劳。

  • 路由:本质是一组 key-value 的对应关系,在前端领域中,key 通常是路径,value 是对应的组件。
  • 路由器:管理多个路由的工具,负责根据路径匹配对应的组件并进行渲染。
  • SPA 应用特点
    • 整个应用只有一个完整的页面
    • 点击导航链接不会刷新页面,只会做局部更新
    • 数据通过 ajax 请求获取

举个例子,当我们访问 /home 路径时,路由器会帮我们渲染 Home 组件;访问 /about 路径时,渲染 About 组件,这就是前端路由的核心作用。

二、路由项目的初始化

2.1 创建项目的时选择路由

在使用 Vue CLI 或 Vite 创建 Vue 项目时,通常会有一个选项让我们选择是否安装 Vue Router,直接勾选即可快速初始化带有路由配置的项目。

2.2 手搓路由(手动配置路由)

假如我们创建项目的时候没有添加路由配置,那我们怎么手动的添加路由配置呢?

①安装 Vue Router(Vue 3 对应版本为 4.x)

npm install vue-router@4

②创建路由配置文件(通常在 src/router/index.ts

src/router/index.ts

// 1、导入创建路由对象(传入工作模式,路由规则):
// 导入createRouter对象, 创建路由对象// 2、导入创建工作模式:
// ①导入createWebHistory对象, 创建历史工作模式
// ②导入createWebHashHistory对象, 创建哈希工作模式
import {createRouter,createWebHistory} from "vue-router";
const roter =  createRouter({history:createWebHistory(),routes:[// 路由规则]
})
// 抛出路由对象,用于挂载到Vue实例中
export default roter

③在src/main.ts挂载到index的#app

src/main.ts

import './assets/main.css'
// 引入刚刚创建的src/router/index.ts router实例
import router from './router'import { createApp } from 'vue'
import App from './App.vue'const app = createApp(App)// 挂载router实例到app实例
app.use(router)app.mount('#app')

③原理的示意图

三、路由的基本使用

3.1 创建路由器

如何创建一个路由器来管理我们的路由规则呢?

// src/router/index.ts
import { createRouter, createWebHistory } from "vue-router";
import Home from "@/pages/Home.vue";
import About from "@/pages/About.vue";// 创建路由器实例
const router = createRouter({history: createWebHistory(), // 路由模式routes: [ // 路由规则数组{path: "/home", // 路径name: "home", // 路由名称component: Home // 对应的组件},{path: "/about",name: "about",component: About}]
});export default router;

3.2 路由的两种工作模式

路由有两种工作模式,它们各有什么特点,该如何选择呢?

3.2.1 history 模式(createWebHistory

const router = createRouter({history: createWebHistory(), // history模式// ...路由规则
});
  • 优点:URL 更加美观,不带有 #,更接近传统网站的 URL
  • 缺点:项目上线后,需要服务端配合处理路径问题,否则刷新页面可能会出现 404 错

3.2.2 hash 模式(createWebHashHistory

const router = createRouter({history: createWebHashHistory(), // hash模式// ...路由规则
});

  • 优点:兼容性更好,不需要服务器端处理路径
  • 缺点:URL 带有 # 不够美观,SEO 优化方面相对较差

总结:开发环境下两种模式均可使用;生产环境如果服务端支持,优先选择 history 模式,否则使用 hash 模式。

3.3 路由的使用(<router-link><router-view>)

路由的使用:

1.路由导航

<router-link to="src" active-class="选中之后的样式类名"></router-link>

2.路由展示

<router-view></router-view>

<template>
<!-- 1、路由导航 --><div class="nav"><!-- to 表示目标路径,active-class 是选中时的样式类名 --><router-link to="/home" active-class="active">首页</router-link><routerLink to="/about" active-class="active">关于</routerLink></div>
<!-- 2、路由展示 --><div class="content"><router-view></router-view></div>
</template><script setup></script><style>
/* 1、路由没有被选中 */
a{color: black;
}
/* 1、路由被选中样式 */
.active {color: #3a5fc6;border: #3a5fc6 1px solid;
}
</style>

3.4 to的三种写法、

<router-link> 的 to 属性有多种写法,分别适用于什么场景呢?

3.4.1 写法一:对象型path写法  :to"{path:'src'}"

 <router-link :to="{path:'/home'}" active-class="active">首页</router-link>

适用于需要动态生成路径或携带参数的场景。

3.4.2 写法二:字符串写法(简写):to:"src"

<routerLink to="/about" active-class="active">关于</routerLink>

适用于路径固定的简单场景,写法简洁。

3.4.3 写法三:对象型name写法  :to"{name:'name'}"

<routerLink :to="{name:'new'}" active-class="active">新页面</routerLink>

需要先在路由规则中配置 name 属性,优点是当路径发生变化时,只需修改路由规则中的 path,不需要修改所有导航链接。

3.4.4 设置replace禁止返回上一个页面

使用replace清除浏览器的历史记录,不能返回上次浏览页面。

<router-link replace :to="{path:'/home'}" active-class="active">首页</router-link>
<routerLink replace to="/about" active-class="active">关于</routerLink>
<routerLink replace :to="{name:'new'}" active-class="active">新页面</routerLink>

四、路由嵌套

在实际开发中,我们经常会遇到页面中嵌套子页面的情况,比如新闻页面中嵌套新闻详情,这时就需要用到嵌套路由。

如何配置嵌套路由呢?

  1. 编写子组件(如 NewsDetail.vue

  2. 在路由规则中使用 children 配置项

// src/router/index.ts
import {createRouter,createWebHistory,createWebHashHistory} from "vue-router";
import Home from "../views/homeView.vue";
import About from "../views/aboutView.vue";
import New from "../views/newView.vue";
import NewList from "../views/newlistView.vue";
const roter =  createRouter({history:createWebHashHistory(),routes:[// 路由规则{path: "/home", // 路径name: "home", // 路由名称component: Home // 对应的组件},{path: "/about",name: "about",component: About},{path: "/New",name: "new",component: New,children:[{path:"NewList",name:"NewList",component:NewList}]},]
})
// 抛出路由对象,用于挂载到Vue实例中
export default roter

注意:

子路由不需要加"/",否则不会被识别为子路由!!!

在新闻页面添加路由导航和路由渲染:

// src/views/newList.vue
<template><h1>我是新闻页面</h1><router-link to="/new/NewList">新闻详情</router-link><router-view></router-view>
</template>

五、路由传参

在页面跳转时,我们经常需要传递参数(如新闻 ID、用户 ID 等),Vue Router 提供了两种主要的传参方式:query 传参和 params 传参

5.1 to + query 传参

query 传参的参数会显示在 URL 中,形如 ?id=1&title=新闻标题

query传参的路径样式:

5.1.1 模板字符串的 query 传参

①路由设置

{path: '/newList',name: 'newList',component: newListView,children:[{// 不要设置参数path: 'newDetail',name: 'newDetail',component: newDetailView,}]
},

②父路由传递参数

<script setup lang="ts">
import { RouterLink, RouterView } from 'vue-router'
import {reactive} from "vue";
const news = reactive([{id: 1001,title: '新闻标题1',content: '新闻内容1'},{id: 1002,title: '新闻标题2',content: '新闻内容2'},{id: 1003,title: '新闻标题3',content: '新闻内容3'},{id: 1004,title: '新闻标题4',content: '新闻内容4'},
])
</script><template><div class="nav" v-for="anew in news" >  // 注意<router-link  :to="`/newList/newDetail?id=${anew.id}&title=${anew.title}&content=${anew.content}`">{{anew.title}}</router-link></div><div class="content"><router-view></router-view></div>
</template><style scoped></style>

③子路由接受参数

<script setup lang="ts">
import { useRoute} from 'vue-router'
const route = useRoute()
</script><template><h2>news详情页面</h2><ul>// 注意怎么访问参数<li>{{route.query.id}}</li><li>{{route.query.title}}</li><li>{{route.query.content}}</li></ul>
</template>
5.1.2 query 传参 + 对象型参数

①路由设置

{path: '/newList',name: 'newList',component: newListView,children:[{// 不要设置参数path: 'newDetail',name: 'newDetail',component: newDetailView,}]
},

②父路由传递参数

<script setup lang="ts">
import { RouterLink, RouterView } from 'vue-router'
import {reactive} from "vue";
const news = reactive([{id: 1001,title: '新闻标题1',content: '新闻内容1'},{id: 1002,title: '新闻标题2',content: '新闻内容2'},{id: 1003,title: '新闻标题3',content: '新闻内容3'},{id: 1004,title: '新闻标题4',content: '新闻内容4'},
])
</script><template><div class="nav" v-for="anew in news" >  // 注意<router-link :to="{path:'/newList/newDetail',query:{id:anew.id,title:anew.title,content:anew.content}}">{{anew.title}}</router-link></div><div class="content"><router-view></router-view></div>
</template>

③子路由接受参数

<script setup lang="ts">
import { useRoute} from 'vue-router'
const route = useRoute()
</script><template><h2>news详情页面</h2><ul>// 注意怎么访问参数<li>{{route.query.id}}</li><li>{{route.query.title}}</li><li>{{route.query.content}}</li></ul>
</template>
5.1.3 name + query 传参 + 对象型参数

①路由设置

{path: '/newList',name: 'newList',component: newListView,children:[{// 不要设置参数path: 'newDetail',name: 'newDetail',component: newDetailView,}]
},

②父路由传递参数

<script setup lang="ts">
import { RouterLink, RouterView } from 'vue-router'
import {reactive} from "vue";
const news = reactive([{id: 1001,title: '新闻标题1',content: '新闻内容1'},{id: 1002,title: '新闻标题2',content: '新闻内容2'},{id: 1003,title: '新闻标题3',content: '新闻内容3'},{id: 1004,title: '新闻标题4',content: '新闻内容4'},
])
</script><template><div class="nav" v-for="anew in news" >  // 注意<router-link :to="{name:'newDetail',query:{id:anew.id,title:anew.title,content:anew.content}}">{{anew.title}}</router-link></div><div class="content"><router-view></router-view></div>
</template>

③子路由接受参数

<script setup lang="ts">
import { useRoute} from 'vue-router'
const route = useRoute()
</script><template><h2>news详情页面</h2><ul>// 注意怎么访问参数<li>{{route.query.id}}</li><li>{{route.query.title}}</li><li>{{route.query.content}}</li></ul>
</template>

5.2 to + params 写法传参

params 传参的参数需要在路由路径中占位,URL 形式如 /news/detail/1/新闻标题

5.2.1 params 传参 + 模板字符串

①路由设置

{path: '/newList',name: 'newList',component: newListView,children:[{// 设置参数为路径的一部分path: 'newDetail/:id/:title/:content',name: 'newDetail',component: newDetailView,}]
},

②父路由传递参数

<script setup lang="ts">
import { RouterLink, RouterView } from 'vue-router'
import {reactive} from "vue";
const news = reactive([{id: 1001,title: '新闻标题1',content: '新闻内容1'},{id: 1002,title: '新闻标题2',content: '新闻内容2'},{id: 1003,title: '新闻标题3',content: '新闻内容3'},{id: 1004,title: '新闻标题4',content: '新闻内容4'},
])
</script><template><div class="nav" v-for="anew in news" >  // 注意<router-link :to="`/newList/newDetail/${anew.id}/${anew.title}/${anew.content}`">{{anew.title}}</router-link></div><div class="content"><router-view></router-view></div>
</template>

③子路由接受参数

<script setup lang="ts">
import { useRoute} from 'vue-router'
const route = useRoute()
</script><template><h2>news详情页面</h2><ul>// 注意怎么访问参数<li>{{route.params.id}}</li><li>{{route.params.title}}</li><li>{{route.params.content}}</li></ul>
</template>

5.2.2 name + params 传参 + 对象型参数

①路由设置

{path: '/newList',name: 'newList',component: newListView,children:[{// 设置参数为路径的一部分path: 'newDetail/:id/:title/:content',name: 'newDetail',component: newDetailView,}]
},

②父路由传递参数

<script setup lang="ts">
import { RouterLink, RouterView } from 'vue-router'
import {reactive} from "vue";
const news = reactive([{id: 1001,title: '新闻标题1',content: '新闻内容1'},{id: 1002,title: '新闻标题2',content: '新闻内容2'},{id: 1003,title: '新闻标题3',content: '新闻内容3'},{id: 1004,title: '新闻标题4',content: '新闻内容4'},
])
</script><template><div class="nav" v-for="anew in news" >  // 注意<router-link :to="{name:'newDetail',params:{id:anew.id, title:anew.title, content:anew.content}}">{{anew.title}}</router-link></div><div class="content"><router-view></router-view></div>
</template>

③子路由接受参数

<script setup lang="ts">
import { useRoute} from 'vue-router'
const route = useRoute()
</script><template><h2>news详情页面</h2><ul>// 注意怎么访问参数<li>{{route.params.id}}</li><li>{{route.params.title}}</li><li>{{route.params.content}}</li></ul>
</template>

5.3  defineProps接受参数小技巧

这样传递过来的参数获取起来大家会不会觉得写起来很复杂,其实使用defineProps就可以很好的解决父组件向子组件传参的问题得到解决:

①在路由中修改

{path: '/newList',name: 'newList',component: newListView,children:[{// 设置参数为路径的一部分path: 'newDetail/:id/:title/:content',name: 'newDetail',component: newDetailView,// 设置为defineProps为tureprops: true,}]
},

②在子组件中修改

<script setup lang="ts">
import { useRoute} from 'vue-router'
const route = useRoute()
// 接受路由参数
defineProps(['id', 'title', 'content'])
</script><template><h2>news详情页面</h2><ul>// 注意怎么访问参数<li>{{id}}</li><li>{{title}}</li><li>{{content}}</li></ul>
</template>

5.4 query 传参 vs params 传参 总结

特点query 传参params 传参
URL 显示带?和 & 符号路径的一部分
路由配置无需特殊配置需要在 path 中占位
跳转方式可使用 path 或 name只能使用 name
刷新页面参数不丢失参数不丢失
适用场景非必需参数(如筛选条件)必需参数(如资源 ID)

六、路由的编程式导航

除了使用 <RouterLink> 组件进行声明式导航,我们还可以通过代码实现编程式导航(如点击按钮跳转,绑定点击事件)。

如何通过代码实现页面跳转呢?

主要导航方法:

6.1 router.push(location, onComplete?, onAbort?)

  • 最常用的方法,向 history 栈添加一个新记录
  • 等同于 <router-link :to="...">
// 字符串路径
router.push('/home')
// 对象
router.push({ path: '/home' })
// 命名的路由
router.push({ name: 'user', params: { userId: '123' } })
// 带查询参数
router.push({ path: '/register', query: { plan: 'private' } })

6.2 router.replace(location, onComplete?, onAbort?)

  • 替换当前 history 栈中的记录,不会留下历史记录
  • 等同于 <router-link :to="..." replace>
router.replace('/home')
router.replace({ path: '/home' })

6.3 router.go(n)

  • 在 history 记录中前进或后退多少步
// 前进一步
router.go(1)
// 后退一步
router.go(-1)
// 前进三步
router.go(3)

6.4 router.back()

  • 等同于 router.go(-1)
  • 后退一步

6.5 router.forward()

  • 等同于 router.go(1)
  • 前进一步

6.6 编程式导航的实现

①在导航页面导入:import {useRoute,useRouter} from 'vue-router'

②创建路由对象:const router = useRouter():因为编程式子导航要使用router的相关方法

③绑定点击事件

④设置绑定事件

示例1:

<script setup lang="ts">
import {useRoute,useRouter} from 'vue-router'
const router = useRouter()   //可以用来实现编程式导航
const tocenter = () => {router.push("/center");
}
function toabout() {router.push({name:'about'})
}
function tohome() {router.push({name:'home'})
}
const tonewList = () => {router.push({path:'/newList'})
}
</script><template><div class="container"><h1>vu3-课堂练习</h1><div class="box"><div class="nav"><ul><li><button @click="tohome">首页</button></li><li><button @click="tonewList">新闻列表</button></li><li><button @click="toabout">关于</button></li><li><button @click="tocenter">用户中心</button></li></ul></div><div class="content"><router-view></router-view></div></div></div>
</template>

示例2:

<script setup lang="ts">
import {useRouter} from 'vue-router'
const userouter = useRouter()
function toback(){userouter.back()
}
function tonext(){userouter.forward()
}
</script>
<template><div class="center">用户中心</div><button v-on:click="toback">返回上一级</button><button @click="tonext">到下一级</button>
</template>

6.7 useRoute和useRouter的区别

useRoute

  • 作用:用于获取当前活跃的路由信息对象(Route 对象)

  • 返回值:一个响应式的路由信息对象,包含当前路由的各种属性

  • 主要属性

    • path:当前路由的路径
    • params:路由参数(如 /user/:id 中的 id
    • query:URL 查询参数(如 ?name=test
    • hash:URL 中的哈希值
    • name:路由名称
    • meta:路由元信息
    • fullPath:完整的 URL 路径,包含查询参数和哈希

useRouter

  • 作用:用于获取路由实例(Router 对象)

  • 返回值:路由实例,包含各种路由操作方法

  • 主要方法

    • push():导航到新路由(类似 router-link 的 to 属性)
    • replace():替换当前路由,不会留下历史记录
    • go(n):在历史记录中前进或后退 n 步
    • back():后退一步,相当于 go(-1)
    • forward():前进一步,相当于 go(1)
    • addRoute():动态添加路由
    • removeRoute():移除路由
  • 使用场景:需要编程式导航或操作路由实例时使用

七、重定向和404

7.1 重定向

什么是重定向?

重定向的核心特点是:浏览器请求A地址,服务器/路由系统告诉浏览器"去B地址",然后浏览器自动跳转到B地址

大家是否看到过浏览器控制台报出这样的警告:

其实本质上的原因就是没有设置重定向,当访问 网址:http://localhost:5173/,浏览器不知道要跳转到哪个路由去,可以设置重定向来解决这一问题:

7.2 404 概念和使用

在 Web 开发里,404 是客户端错误状态码 ,当服务器找不到对应请求的资源(比如页面、接口数据等)时,就会返回 404 响应 。在前端路由场景中,404 主要用来处理用户访问不存在的路由路径,让用户看到友好的 “页面未找到” 提示,而非空白或报错页面,提升体验。

比如访问不存在的路径的时候就会跳转到404页面:

①在src/index.ts 路由配置中设置:

    {path: "/:pathMatch(.*)*",  // 匹配所有未定义的路径name: "notFind",component: NotFind,}

②设置NotFind页面

这样当我们访问不存在的页面的时候就会自动跳转到404页面啦!!!

八、路由守卫(补充内容)

路由守卫可以控制路由的访问权限,比如未登录用户不能访问个人中心页面。

8.1 全局前置守卫

// src/router/index.ts
router.beforeEach((to, from, next) => {// to:即将进入的路由// from:即将离开的路由// next():允许导航,next('/login'):跳转到登录页,next(false):阻止导航// 判断是否需要登录权限if (to.meta.requiresAuth) {// 检查是否登录(这里假设登录信息存储在 localStorage 中)const token = localStorage.getItem("token");if (token) {next(); // 已登录,允许访问} else {next("/login"); // 未登录,跳转到登录页}} else {next(); // 不需要登录,允许访问}
});

使用时需要在路由规则中添加 meta 属性:

{path: "/profile",name: "profile",component: Profile,meta: { requiresAuth: true } // 表示需要登录权限
}

掌握这些知识点后,你可以轻松实现单页应用的路由管理,包括页面跳转、参数传递、权限控制等功能。在实际开发中,需要根据具体场景选择合适的路由配置和传参方式,让你的应用更加灵活和高效。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如若转载,请注明出处:http://www.pswp.cn/diannao/94507.shtml
繁体地址,请注明出处:http://hk.pswp.cn/diannao/94507.shtml
英文地址,请注明出处:http://en.pswp.cn/diannao/94507.shtml

如若内容造成侵权/违法违规/事实不符,请联系英文站点网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

深入理解设计模式:策略模式的艺术与实践

在软件开发中&#xff0c;我们经常会遇到需要根据不同情况选择不同算法或行为的场景。传统的做法可能是使用大量的条件语句&#xff08;if-else或switch-case&#xff09;&#xff0c;但随着需求的增加和变化&#xff0c;这种硬编码的方式会导致代码难以维护和扩展。策略模式&a…

概率/期望 DP llya and Escalator

题目链接&#xff1a;Problem - D - Codeforces 看了这篇文章来的&#xff1a;【算法学习笔记】概率与期望DP - RioTian - 博客园 这篇博客写得挺好的&#xff0c;讲了一些常见方法&#xff0c;概率 / 期望的题多练练就上手了。 题目大意&#xff1a; n 个人排队上电梯&…

大陆电子MBDS开发平台转到其他国产控制器平台产生的问题记录

u8_StComLowSpdGearSwt变量为例&#xff0c;之前用的时候只有输入&#xff0c;没什么实际意义&#xff0c;导致新环境下编译报错&#xff0c;缺少声明&#xff0c;解决办法&#xff1a;注释掉输入模块。今天解决的另一个比较大的问题&#xff0c;不同模型函数公用函数模块生成代…

机器学习模型调优实战指南

文章目录模型选择与调优&#xff1a;从理论到实战1. 引言2. 模型评估&#xff1a;为选择提供依据2.1 偏差-方差权衡2.2 数据集划分与分层抽样2.3 交叉验证&#xff08;Cross-Validation&#xff09;2.4 信息准则&#xff08;AIC / BIC&#xff09;3. 超参数调优&#xff1a;让模…

【教程】Unity CI/CD流程

测试机&#xff1a;红帽 Linux8 源码仓库&#xff1a;Gitee - MrRiver/Unity Example   系统环境准备 1&#xff09;yum 源 sudo curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-8.repo sudo sed -i s/\$releasever/8/g /etc/yum.repos…

文献阅读 | Briefings in Bioinformatics | Hiplot:全面且易于使用的生物医学可视化分析平台

文献介绍文献题目&#xff1a; Hiplot&#xff1a;一个综合且易于使用的 Web 服务&#xff0c;用于增强出版物准备的生物医学数据可视化 研究团队&#xff1a; Openbiox/Hiplot 社区 发表时间&#xff1a; 2022-07-05 发表期刊&#xff1a; Briefings in Bioinformatics 影响因…

【数字图像处理系列笔记】Ch04:灰度变换与空间域图像增强(2)

目录 一、空域滤波基础 一、空域滤波的基本概念 二、空域滤波的数学原理 三、空域滤波器的分类与典型示例 &#xff08;一&#xff09;线性滤波器&#xff08;Linear Filter&#xff09; &#xff08;二&#xff09;非线性滤波器&#xff08;Non-linear Filter&#xff0…

AI浪潮下,FPGA如何实现自我重塑与行业变革

引言&#xff1a;AI 与 FPGA&#xff0c;新时代的碰撞 2025 年&#xff0c;人工智能技术迎来爆发式增长&#xff0c;大模型、生成式 AI 和多模态技术持续突破&#xff0c;人形机器人量产元年正式开启&#xff0c;自动驾驶商业化进程加速&#xff0c;工业数字化转型全面铺开(1)…

系统集成项目管理工程师【第十一章 规划过程组】定义范围、创建WBS、规划进度管理和定义活动篇

系统集成项目管理工程师【第十一章 规划过程组】定义范围、创建WBS、规划进度管理和定义活动篇 一、定义范围&#xff1a;给项目画好"边界线" 定义范围是明确项目和产品"做什么、不做什么"的过程&#xff0c;直接影响后续所有工作的方向。 1. 核心概念与作…

Spring Boot 参数校验全指南

Spring Boot 参数校验全指南 在 Web 开发中&#xff0c;参数校验是保障接口安全性和数据合法性的关键环节。手动编写校验逻辑不仅繁琐&#xff0c;还容易遗漏边界情况。Spring Boot 整合了 validation 工具&#xff0c;提供了一套简洁高效的参数校验方案&#xff0c;可快速实现…

常用技术资料链接

1.team技术 https://zhuanlan.zhihu.com/p/11389323664 https://blog.csdn.net/Lucky_Lu0/article/details/121697151 2.bond切换主备 https://www.xgss.net/3306.html 3.ssh详解&#xff1a; https://cloud.tencent.com/developer/news/105165 https://blog.huochengrm.c…

【Spring Cloud】-- 注册中心

文章目录1. 什么是注册中心2. CPA理论1. 什么是注册中心 注册中心有三种角色&#xff1a; 服务提供者&#xff08;Server&#xff09; &#xff1a;提供接口给其他微服务的程序。服务消费者&#xff08;Client&#xff09;&#xff1a;调用其他微服务提供的接口。**服务注册中…

go-zero 详解

go-zero 详解 go-zero 是一个基于 Go 语言的微服务框架&#xff0c;由字节跳动团队开发并开源&#xff0c;旨在帮助开发者快速构建高可用、高性能的微服务架构。它集成了丰富的组件&#xff0c;简化了微服务开发中的常见问题&#xff08;如服务注册发现、配置管理、限流熔断等&…

接口自动化框架封装之统一请求封装及通过文件实现接口关联

接口自动化测试框架封装目的:简化自动化框架的落地,提高投入和产出比,只要一个人封装好框架,另外的测试通过写yaml测试用例即可实现接口自动化1.统一请求的封装去除多余重复的代码可跨py文件实现通过一个session来自动关联有cookie的接口设置统一公共参数,统一文件处理,统一异常…

Vue 最佳实践:如何利用唯一 key 值保证 el-table 动态渲染的稳定性

&#x1f4cb; 问题描述 在Vue 2.0 ElementUI项目的偏置条件管理页面中&#xff0c;每次切换到"内规拉偏"菜单时&#xff0c;表格样式会发生崩溃&#xff0c;导致表格布局异常、列宽错乱、固定列显示不正确等问题。 &#x1f50d; 问题分析 通过深入分析代码&#x…

popen开启进程,写入数据

通过管道&#xff08;popen&#xff09;启动 SDIWAN_WEB 进程并写入 JSON 数据的过程可以分为以下步骤&#xff0c;结合代码示例和关键注意事项进行说明&#xff1a;1. 核心代码示例 #include <stdio.h> #include <json-c/json.h>int main() {// 1. 创建 JSON 对象…

计算机视觉的四项基本任务辨析

计算机视觉是使计算机能理解采集设备采集的图像视频的一门学科&#xff0c;目的是让计算机实现人的视觉功能——对客观世界的三维场景的感知、识别和理解。换句话说&#xff0c;要让计算机具备通过二维图像认识三维环境的能力。 目录 三个阶段 视觉层级 基本任务 技术难点…

iostat 系统IO监控命令学习

一、iostat 命令描述 “iostat”命令用于监测系统输入/输出设备的负载情况&#xff0c;其通过观察设备处于活跃状态的时间与平均传输速率之间的关系来实现这一目的。该命令会生成报告&#xff0c;这些报告可用于调整系统配置&#xff0c;以更好地平衡物理磁盘之间的输入/输出负…

jenkins使用ssh方式连接gitee 公钥、私钥配置、指纹

前言 Gitee 提供了基于 SSH 协议的 Git 服务&#xff0c;jenkins可使用ssh方式连接gitee&#xff0c;拉取代码、提交tag等&#xff1b;使用ssh 连接&#xff0c;相比用户名密码方式&#xff0c;可省去因密码变更而引起的jenkins关联修改。 gitee生成、添加 SSH 公钥 生成SSH…

如何在Android设备上删除多个联系人(3种方法)

如果您想清理安卓手机&#xff0c;或者只是想删除旧的、不需要的联系人&#xff0c;或者删除多个联系人&#xff0c;有三种有效的方法可供选择。无论您是想手动删除安卓手机上的联系人&#xff0c;还是使用专用工具&#xff0c;都可以按照以下步骤操作。方法1&#xff1a;如何通…