Vue全家桶(四):Vue Router 路由

news2024/9/20 20:31:50

目录

  • Vue Router
    • 1. 相关理解
      • 1.1 Vue Router的理解
      • 1.2 对SPA应用的理解
      • 1.3 路由的理解
    • 2. 基本路由
      • 2.1 vue-router使用步骤
      • 2.2 几个注意点
      • 2.3 触发路由
      • 2.4 嵌套路由
      • 2.5 路由传递参数方式
        • 2.5.1 params 方式
        • 2.5.2 Query的方式
      • 2.6 命名路由
      • 2.7 路由的props配置
      • 2.8 路由跳转的replace方法
      • 2.9 编程式路由导航
      • 2.10 重定向和别名
      • 2.11 两个生命周期钩子 activated、deactivated
      • 2.12 keep-alive缓存路由
      • 2.13 路由守卫

Vue Router

1. 相关理解

1.1 Vue Router的理解

Vue的一个插件库,专门用来实现SPA应用

1.2 对SPA应用的理解

  1. 单页 Web 应用 (single page web application,SPA
  2. 整个应用只有一个完整的页面
  3. 点击页面中的导航链接不会刷新页面,只会做页面的局部更新
  4. 数据需要通过 ajax 请求获取

在这里插入图片描述

1.3 路由的理解

  1. 什么是路由?
  • 一个路由就是一组映射关系(key - value),多个路由需要路由器(router)进行管理
  • key为路径,value可能是function或component

在开发中,路由分为后端路由和前端路由
2. 路由分类
1)后端路由
i. 概念:根据不同的用户URL 请求,返回不同的内容,value是function,用于处理客户端提交的请求
ii.本质:服务器接收到一个请求时,根据请求路径找到匹配的函数来处理请求,返回响应数据

后端路由根据不同的URL地址分发不同的资源
在这里插入图片描述

2)前端路由
i. 概念:根据不同的用户事件,显示不同的页面内容,value是component,用于展示页面内容
ii. 本质:当浏览器的路径改变时,对应的组件就会显示
前端路由负责事件监听,触发事件后通过事件函数渲染不同内容
在这里插入图片描述

2. 基本路由

2.1 vue-router使用步骤

  1. 安装vue-router命令:npm i vue-router@3
    vue2版本使用vue-router的3版本
    vue3版本使用vue-router的4版本
  2. 应用插件:Vue.use(VueRouter)
  3. 编写router配置项 router/index.js

文件目录结构
在这里插入图片描述

Vue2的vue-router

import Vue from 'vue'
import VueRouter from 'vue-router'
import HomeView from '../views/HomeView.vue'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    name: 'home',
    component: HomeView
  },
  {
    path: '/about',
    name: 'about',
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () => import(/* webpackChunkName: "about" */ '../views/AboutView.vue')
  }
]

//创建router实例对象,去管理一组的路由规则
const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

//暴露router
export default router

Vue3的vue-router

import { createRouter, createWebHistory } from 'vue-router'
//引入组件
import Home from '../views/Home.vue'
import About from '../views/About.vue'
//等价于
//const Home = () => import('../views/Home.vue')
//const About = () => import('../views/About.vue')

//声明一个路由规则,访问home,加载Home组件
const routes = [
  {
    path: '/',
    name: 'Home',
    component: Home
  },
  {
    path: '/about',
    name: 'About',
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () => import(/* webpackChunkName: "about" */ '../views/About.vue')
  }
]

// 创建一个路由
const router = createRouter({
  //模式为历史模式,请求过的路由会push,类似于window.history.pushState() 
  history: createWebHistory(process.env.BASE_URL),
  //路由规则
  routes
})
//缺省暴露路由
export default router

src/main.js
在这里插入图片描述

  1. 路由的三种模式

hash模式:
使用URL的hash值来作为路由,用来指导浏览器动作,对服务器端完全无用,支持所有浏览器

对于一个url来说,什么是hash值?—— #及其后面的内容就是hash值。
hash值不会包含在 HTTP 请求中,即:hash值不会带给服务器。

  • 地址中永远带着#号,不美观 。
  • 若以后将地址通过第三方手机app分享,若app校验严格,则地址会被标记为不合法。
  • 兼容性较好。

history模式:

  • 地址干净,美观 。
  • 兼容性和hash模式相比略差。
  • 应用部署上线时需要后端人员支持,解决刷新页面服务端404的问题。

在这里插入图片描述

abstract模式:
支持所有JavaScript运行模式,如果发现没有浏览器的API,路由会自动强制进入这个模式。

  1. 路由两种自带标签
  1. 实现切换
    <router-link></router-link> 浏览器会倍替换为a标签
    active-class 可配置高亮样式
<router-link active-class="active" to="/">Home</router-link> 

2)展示指定位
<router-view></router-view>

2.2 几个注意点

  1. 路由组件通常存放在 pages 文件夹,一般组件通常存放在 components 文件夹
    路由组件:是指由路由渲染出来的组件,由<router-view>渲染弄出来的组件
    一般组件:一般要写组件标签,如<Banner/>
    比如上一节的案例就可以修改为
    src/pages/Home .vue
    src/pages/About.vue
    src/router/index.js
    src/components/Banner.vue
    src/App.vue

  2. 通过切换,“隐藏”了的路由组件,默认是被销毁掉的,需要的时候再去挂载。

  3. 每个组件都有自己的$route属性,里面存储着自己的路由信息。

  4. 整个应用只有一个router,可以通过组件的$router属性获取到。

路由有两种全局属性
$route : 当前正在访问的路由
$router:代表整个大的路由器的对象

2.3 触发路由

App.vue 触发路由的几种操作

<template>
  <div id="nav">
	<!-- router-link与a标签相比有事件处理程序,会渲染成a标签,to指定路径,放到URL中-->
    <router-link to="/">Home</router-link> |
    <router-link to="/about" >关于</router-link> |
    <router-link to="/about" custom v-slot="{ navigate }">
      <button @click="navigate" @keypress.enter="navigate" role="link">关于</button>
    </router-link> |
    <button :class="{active:$route.path='/user'}" @click="$router.push('/user')">个人中心</button>|
    <button @click="$router.go(-1)">返回</button>|
    {{$route.path}}
  </div>
  <hr>
  <router-view/>
</template>

在这里插入图片描述
在这里插入图片描述
若要一个页面显示三个不同的组件
App.vue

<template>
  <div id="nav">
<!--     router-link与a标签相比有事件处理程序,会渲染成a标签,to指定路径,放到URL中-->
    <router-link to="/">Home</router-link> |
    <router-link to="/about" >关于</router-link> |
    <router-link to="/about" custom v-slot="{ navigate }">
      <button @click="navigate" @keypress.enter="navigate" role="link">关于</button>
    </router-link> |
    <button :class="{active:$route.path=='/user'}" @click="$router.push('/user')">个人中心</button>|
    <button @click="$router.go(-1)">返回</button>|
    {{$route.path}}
  </div>
  <hr>
  <!-- name对应组件名称,中间一个缺省为home-->
  <router-view class="one" name="User"></router-view>
  <router-view class="two" ></router-view>
  <router-view class="three" name="About"></router-view>
</template>

<style>
#app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
}
#nav {
  padding: 30px;
}
#nav a {
  font-weight: bold;
  color: #2c3e50;
}
#nav a.router-link-exact-active {
  color: #42b983;
}
.active {
  color: red !important
}
.one {
  width: 25%;
  height: 300px;
  float: left;
  background-color: #42b983;
}
.two {
  width: 50%;
  height: 300px;
  float: left;
  background-color: cornflowerblue;
}
.three {
  width: 25%;
  height: 300px;
  float: left;
  background-color: coral;
}
</style>

index.js

import { createRouter, createWebHistory } from 'vue-router'
import Home from '../views/Home.vue'
import User from '../views/User.vue'
import About from '../views/About.vue'
const routes = [
  {
    path: '/',
    name: 'Home',
    //对象格式,排序也有关系的
    components: {
      default: Home,
      About,
      User
    }
    // component: Home
  },
  {
    path: '/user',
    name: 'user',
    component: User
  },
  {
    path: '/about',
    name: 'About',
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () => import(/* webpackChunkName: "about" */ '../views/About.vue')
  }
]

const router = createRouter({
  history: createWebHistory(process.env.BASE_URL),
  routes
})

export default router

在这里插入图片描述
在这里插入图片描述

2.4 嵌套路由

  1. 配值路由规则,使用children配置项
    router/index.js路由设置
import { createRouter, createWebHistory } from 'vue-router'
import Home from '../views/Home.vue'
import User from '../views/User.vue'
import About from '../views/About.vue'
import Order from '../views/UserOrder.vue'
import Setting from '../views/UserSetting.vue'

//等价于
//const Home = () => import('../views/Home.vue')
//const About = () => import('../views/About.vue')
import * as path from "path";
const routes = [
  {
    path: '/',
    name: 'Home',
    component: Home
  },
  {
    path: '/user',
    name: 'user',
    component: User,
    //子路由,/user/order
    children: [
        //设置默认组件
      {
        path: '',
        component: Order
      },
      {
        path: 'order',    //此处不要带斜杠
        component: Order
      },
      {
        path: 'setting',
        component: Setting
      }
    ]
  },
  {
    path: '/about',
    name: 'About',
    component: () => import(/* webpackChunkName: "about" */ '../views/About.vue')
  }
]

const router = createRouter({
  history: createWebHistory(process.env.BASE_URL),
  routes
})

export default router

  1. 跳转
    <router-link to="/user/order">我的订单</router-link>

User.vue

<template>
  <div class="about">
    <h1>This is an User page</h1>
    <br>
    <div class="menu">
      <ul>
        <!-- 跳转要写完整路径 -->
        <li><router-link to="/user/order">我的订单</router-link></li>
        <li><router-link to="/user/setting">个人设置</router-link></li>
      </ul>

    </div>
    <div class="content">
      <router-view></router-view>
    </div>

  </div>
</template>
<script>
export default {
  name: "User"
}
</script>
<style scoped>
.menu {
  width: 30%;
  height: 300px;
  background-color: #42b983;
  float: left;
}
.content {
  width: 70%;
  height: 300px;
  background-color: floralwhite;
  float: right;
}
</style>

在这里插入图片描述

在这里插入图片描述

2.5 路由传递参数方式

在这里插入图片描述
上个嵌套路由的例子,“我的订单”和“个人设置”是采用切换组件来实现,下边采用传递参数来实现页面的切换,即同个模板,传递参数值来切换

2.5.1 params 方式

  1. 传递参数

User.vue

<template>
  <div >
    <h1>This is an User page</h1>
    <br>
    <div class="menu">
        ……
      <ul>
        <li v-for="item in article">
         <!-- 采用:to的形式,否则双引号的内容不生效,无法成/user/page/10的格式-->
         
		 <!-- to的字符串写法一-->
          <router-link :class="{active:$route.params.pid==item.id}" :to="'/user/page/'+item.id">{{item.title}}</router-link>
          
          <!-- to的字符串写法 -多参数写法二 -->
          <router-link :class="{active:$route.params.pid==item.id}" :to="`/user/page/${item.id}/${item.title}`">{{item.title}}</router-link>
          
		 <!-- to的对象写法-->
          <router-link :class="{active:$route.params.pid==item.id}" 
          				:to="{
          					name:'newPage',
          					params: {pid:item.id}">{{item.title}}</router-link>
        </li>
      </ul>
    </div>
    <div class="content">
      <router-view></router-view>
    </div>
  </div>
</template>
<script>
export default {
  name: "User",
  data(){
    return {
      article: [
        {id:10, title: '这是文章一'},
        {id:11, title: '这是文章二'},
        {id:12, title: '这是文章三'},
        {id:13, title: '这是文章四'},
        {id:14, title: '这是文章五'},
      ]
    }
  }
}
</script>
<style scoped>...</style>

特别注意:路由携带params参数时,若使用to的对象写法,则不能使用path配置项,必须使用name配置!

添加一个UserPage.vue

<template>
  <h2>这是文章的模板</h2>
  <!--  $route当前路由,获取参数-->
  文章ID:{{$route.params.pid}}
  <br>
  <h1>{{pageid}}</h1>
</template>

<script>
export default {
  name: "UserPage",
  computed: {
    pageid() {
    //获取当前路由属性的参数值pid
      return this.$route.params.pid;
    }

  }
}
</script>
<style scoped></style>

router/index.js路由配置

const routes = [
  ……
  {
    path: '/user',
    name: 'user',
    component: User,
    //子路由,/user/order
    children: [
        //设置默认组件
     ……
      {
       //动态路由配置
       	name: 'newPage',            //to的对象写法,要有name配置
        path: 'page/:pid',          //如果由多个参数则为 path: 'page/:pid/:title/:xxx' 这样的写法
        component: Page
      }
    ]
  },
  ……
]

在这里插入图片描述

2.5.2 Query的方式

User.vue

<template>
  <div>
    <h1>This is an User page</h1>
    <br>
    <div class="menu">
     ……
      <ul>
        ……
        <br>
		<!-- 三种格式-->
		<!-- to的字符串写法一 -->
        <li><router-link to="/user/article?name=zs&age=10">文章一</router-link></li>
        <!-- to的字符串写法二 -->
        <li><router-link :to="`/user/article?name=${item.name}&age=${item.age}`">文章一</router-link></li>
        
		<!-- to的对象写法(推荐) -->
        <li>
        	<router-link :to="{
        					path:'/user/article', 
        					query:{
        						name:'lisi', 
        						age:20
        					}}">文章二</router-link>
        </li>
        <br>
        <li><button @click="$router.push({path:'/user/article', query: {name:'word', age:99}})">文章三</button></li>
      </ul>
    </div>
    <div class="content">
      <router-view></router-view>
    </div>

  </div>
</template>
<script>
export default {
  name: "User",
  data(){
    return {
      article: [
        ……
      ]
    }
  }
}
</script>
<style scoped>……</style>

添加一个Article.vue

<template>
  这是文章内容
  <br>
  name:{{$route.query.name}}<br>
  age:{{$route.query.age}}<br>
</template>

<script>
export default {
  name: "Article"
}
</script>
<style scoped></style>

router/index.js路由配置

const routes = [
  ……
  {
    path: '/user',
    name: 'user',
    component: User,
    //子路由,/user/order
    children: [
        //设置默认组件
     ……
      {
        path: 'article',     //正常配置
        component: Article
      }
    ]
  },
  ……
]

在这里插入图片描述

2.6 命名路由

作用:可以简化路由的跳转
如何使用?

  1. 给路由命名
{
	path:'/demo',
	component:Demo,
	children:[
		{
			path:'test',
			component:Test,
			children:[{
                    name:'hello' //给路由命名
					path:'welcome',
					component:Hello,
				}
			]
		}
	]
}

  1. 简化跳转
<!--简化前,需要写完整的路径 -->
<router-link :to="/demo/test/welcome">跳转</router-link>

<!--简化后,直接通过名字跳转 -->
<router-link :to="{name:'hello'}">跳转</router-link>

<!--简化写法配合传递参数 -->
<router-link 
	:to="{
		name:'hello',
		query:{
		   id:666,
           title:'你好'
		}
	}"
>跳转</router-link>

2.7 路由的props配置

props作用:让路由组件更方便的收到参数,不用一个个的写$route.query.xxx

{
	name:'xiangqing',
	path:'detail/:id',
	component:Detail,

	//第一种写法:props值为对象,该对象中所有的key-value的组合最终都会通过props传给Detail组件
	// props:{a:900}

	//第二种写法:props值为布尔值,布尔值为true,则把路由收到的所有params参数通过props传给Detail组件,不会理会query参数
	// props:true
	
	//第三种写法:props值为函数,该函数返回的对象中每一组key-value都会通过props传给Detail组件
	props($route) {
		return {
		  id: $route.query.id,
		  title:$route.query.title,
		  a: 1,
		  b: 'hello'
		}
	}
}

跳转去组件的具体代码

<template>
  <ul>
      <h1>Detail</h1>
      <li>消息编号:{{id}}</li>
      <li>消息标题:{{title}}</li>
      <li>a:{{a}}</li>
      <li>b:{{b}}</li>
  </ul>
</template>

<script>
export default {
    name: 'Detail',
    //使用props接受路由参数
    props: ['id', 'title', 'a', 'b'],
    mounted () {
        console.log(this.$route);
    }
}
</script>
<style></style>

2.8 路由跳转的replace方法

  1. 作用:控制路由跳转时操作浏览器历史记录的模式
  2. 浏览器的历史记录有两种写入方式:pushreplace
  • push是追加历史记录
  • replace是替换当前记录,路由跳转时候默认为push方法
  1. 开启replace模式
<router-link :replace="true" ...> News</router-link>
//简写
<router-link replace ...> News</router-link>

总结: 浏览记录本质是一个栈,默认 push ,点开新页面就会在栈顶追加一个地址,后退,栈顶指针向下移动,改为 replace 就是不追加,而将栈顶地址替换

2.9 编程式路由导航

  1. 声明式导航:通过点击链接实现导航的方式 例如:普通网页中的<a></a> 链接或vue 中的<router-link></router-link>
  2. 编程式导航:通过调用JavaScript形式的API实现导航的方式 例如:普通网页中的location.href
    编程式路由导航作用:不借助<router-link>实现路由跳转,让路由跳转更加灵活
    具体参数规则:
// 字符串(路径名称)
this.$router.push('/home')
// 对象
this.$router.push({ path: '/home' })
// 命名的路由(传递参数)
this.$router.push({ name: '/user', params: { userId: 123 }})
// 带查询参数,变成/register?uname=lisi
this.$router.push({ path: '/register', query: { uname: 'lisi' }})

this.$router.replace({
	name:'xiangqing',
		params:{
			id:xxx,
			title:xxx
		}
})
this.$router.forward() //前进
this.$router.back() //后退
this.$router.go(n) //可前进也可后退,n大于0前进n,小于0后退n

使用

<button @click="$router.go(-1)">返回</button>
<button @click="pushShow(m)">push查看</button>
<script>
...
methods: {
	pushShow(m) {
		this.$router.push({ path: '/register', query: {id: m.id, name: m.title }})
	}
}
...
</script>

2.10 重定向和别名

在这里插入图片描述

2.11 两个生命周期钩子 activated、deactivated

activateddeactivated是i路由组件所独有的两个钩子,用于捕获路由组件的激活状态
具体使用:
activatedkeep-alive 缓存的组件激活时调用。
deactivatedkeep-alive 缓存的组件失活时调用。
activateddeactivated是配合keep-alive一起使用的,其余不会触发,

在存在keep-alive的时候可以将activated当作created进行使用
deactivated是组件销毁的时候触发,此时的destory是不执行的

2.12 keep-alive缓存路由

keep-alive作用:主要用于保留组件状态或避免重新渲染。 包裹动态组件时,会缓存不活动的组件实例,而不是销毁它们。

Props:

  • include:只有名称匹配的组件会被缓存。
  • exclude:任何名称匹配的组件都不会被缓存。
  • max:最多可以缓存多少组件实例。

router-view是vue-router内置组件,如果直接包含在keep-alive里面,所有路径匹配到的组件都会被缓存

场景:用户在表单输入的时候,如果切换了页面再返回,表单输入的内容都被清空了,这是因为组件在切换时,会已处在创建-销毁的过程中,为节省时间和资源,采用keep-alive使其保存在缓存中

	created() {
      console.log('About---组件创建');
    },
    unmounted() {
      console.log('About---组件被销毁');
    },
    activated() {
      console.log('About---keep-alive 缓存的组件激活时调用');
    },
    deactivated() {
      console.log('About---keep-alive 缓存的组件停用时调用');
    }

在这里插入图片描述

include设置想要缓存的组件名

//缓存一个路由组件
<keep-alive include="News">     //include中写想要缓存的组件名,不写表示全部缓存
    <router-view></router-view>
</keep-alive>

//缓存多个路由组件
<keep-alive :include="['News','Message']"> 
    <router-view></router-view>
</keep-alive>

只要将router-view修改如下代码,就可实现缓存效果

<router-view v-slot="{ Component }">
    <transition>
      <keep-alive>
        <component :is="Component" />
      </keep-alive>
    </transition>
  </router-view>

这种方法会触发actived()deactivated()方法
在这里插入图片描述
可单独设置exclude使得某些组件不缓存

<router-view v-slot="{ Component }">
    <transition>
      <keep-alive exclude="About">
        <component :is="Component" />
      </keep-alive>
    </transition>
  </router-view>

在这里插入图片描述
为了保证离开一个页面后再返回仍停留在离开时的状态,可在组件内设置前置守卫,将离开时的路径保存下来,待缓存激活active时再设置全局路由

 created() {
    console.log('User---组件创建');
  },
  unmounted() {
    console.log('User---组件被销毁');
  },
  activated() {
    console.log('User---keep-alive 缓存的组件激活时调用');
    //回到离开时的状态
    this.$router.push(this.path)
  },
  deactivated() {
    console.log('User---keep-alive 缓存的组件停用时调用');
  },
  beforeRouteLeave(to,from) {
    //获取离开的路由
    this.path = from.fullPath
    console.log('to----'+to.fullPath);
    console.log('from----'+from.fullPath);
  }

2.13 路由守卫

作用:对路由进行权限控制
分类:全局守卫、独享守卫、组件内守卫

  1. 全局守卫

前置守卫:从一个路由跳转另一个路由之前有一个前置守卫,前置守卫会调用一个方法,这个方法可以处理跳转之前的事情。如登录访问
在这里插入图片描述

后置守卫:跳转过去之后,在内容没显示之前,有一个后置钩子
在这里插入图片描述

router/index.js

const routes = [
  {
    path: '/home',
    name: 'Home',
    //重定向到根 两种方式
    // redirect: '/',
    redirect: {name: 'root'},
    component: Home,
    meta: {
      title: '首页'
    },
  }]
  
const router = new VueRouter({
	routes 
})

//全局前置守卫:初始化时执行、每次路由切换前执行
router.beforeEach((to,from)=>{
  console.log('前置守卫');
  //设置即将到达的页面标题,meta是上方各个路由设置的meta属性
  document.title = to.meta.title
  console.log('title---'+to.meta.title);
  //打印即将到达的路径
  console.log('to---'+to.fullPath);
  //false不准跳转,true则放行
  return true;
})

//全局后置守卫:初始化时执行、每次路由切换后执行
router.afterEach((to,form)=>{
  console.log('后置钩子');
  console.log('to---'+to.fullPath);
  console.log('form---'+form.fullPath);
})

export default router

在这里插入图片描述

const routes = [
  {
    path: '/home',
    name: 'Home',
    component: Home,
    meta: {
      isAuth: true,
      title: '首页'
    },
  }]
  
const router = new VueRouter({
	routes 
})

//全局前置守卫:初始化时执行、每次路由切换前执行
router.beforeEach((to, from, next) => {
	if(to.meta.isAuth) {         //判断当前路由是否需要进行权限控制
		if(localStorage.getItem('school') === 'zhejiang'){ //权限控制的具体规则
			next() //放行
		}else{
			alert('暂无权限查看')
			// next({name:'guanyu'})
		}
	}else{
		next() //放行
	}

//全局后置守卫:初始化时执行、每次路由切换后执行	
router.afterEach((to,from)=>{
	if(to.meta.title){ 
		document.title = to.meta.title //修改网页的title
	}else{
		document.title = 'vue_test'
	}
})
  1. 独享守卫
    独享守卫是在routes 子路由内写守卫
beforeEnter(to, from, next){
	if(to.meta.isAuth) {         //判断当前路由是否需要进行权限控制
		if(localStorage.getItem('school') === 'zhejiang'){ //权限控制的具体规则
			next() //放行
		}else{
			alert('暂无权限查看')
			// next({name:'guanyu'})
		}
	}else{
		next() //放行
	}
}

在这里插入图片描述

  1. 组件内守卫
    组件内守卫是在具体组件内写守卫
//进入守卫:通过路由规则,进入该组件时被调用
beforeRouteEnter (to, from, next) {
},
//离开守卫:通过路由规则,离开该组件时被调用
beforeRouteLeave (to, from, next) {
}

在这里插入图片描述

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

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

H3C-HCL模拟器-VLAN划分实验

一、实验拓扑结构图&#xff1a; 二、实验需求&#xff1a; 1. 按图示为PC配置IP地址 2. SW1和SW2上分别创建vlan10和vlan20&#xff0c;要求PC3和PC5属于vlan10&#xff0c;PC4和PV6属于vlan20 3. SW1和SW2相连的接口配置为trunk类型&#xff0c;允许vlan10和vlan20通过 4…

AI工程化的“基座能力”?—— 聊聊GPT Function Calling

点击↑上方↑蓝色“编了个程”关注我~ 这是Yasin的第 94 篇原创文章 最近AI大模型火出了圈&#xff0c;很多人惊叹它的智能程度。但大多数人都以为它的能力主要在“聊天”、“写文案”这方面。然而实际它能做的远远更多。 Chat GPT是当今世界上最智能的模型&#xff0c;它前段时…

【Linux】—— 详解进程PCB和进程状态

前言&#xff1a; 在上篇我们已经对有关体系结构的基本知识进行了详细的介绍&#xff0c;接下来我们将进入网络编程的第一个大块—— 有关进程相关的知识&#xff01;&#xff01;&#xff01; 目录 前言 &#xff08;一&#xff09; 基本概念 1、描述进程-PCB 2、查看进程…

【人工智能】— 逻辑回归分类、对数几率、决策边界、似然估计、梯度下降

【人工智能】— 逻辑回归分类、对数几率、决策边界、似然估计、梯度下降 逻辑回归分类Logistic Regression ClassificationLogistic Regression: Log OddsLogistic Regression: Decision BoundaryLikelihood under the Logistic ModelTraining the Logistic ModelGradient Desc…

使用vue脚手架搭建前端工程(附:搭配ElementUI来快速开发)

目录 一、搭建过程 1. 全局安装webpack&#xff08;打包工具&#xff09; 2. 全局安装vue脚手架 3. 初始化vue项目 4. vue项目目录的简单介绍 二、执行流程分析 三、自己造一个组件案例 四、ElementUI的使用 1. 环境的引入 2. 一个简单使用 3. 使用它来快速搭建后台管…

AI绘画Stable diffusion保姆级教程,看这一篇就够了「安装-配置-画图」

随着chat gpt爆火之后&#xff0c;越来越多的人开始关注人工智能&#xff0c;人工智能相关的其他应用如AI绘画&#xff0c;也再次得到人们的关注。AI绘画的确很上头&#xff0c;最近几天小编也研究一下&#xff0c;这里把研究的过程以及中间遇到的问题整理一下&#xff0c;我这…

吴恩达471机器学习入门课程3第1周——异常检测

异常检测 1 导包2 - 异常检测2.1 问题陈述2.2 数据集可视化您的数据 2.3 高斯分布2.2.1 估计高斯分布的参数2.2.2 选择阈值 ϵ \epsilon ϵ2.4 高维数据集异常检测 实现异常情况检测算法&#xff0c;并应用它来检测网络上的故障服务器。 1 导包 import numpy as np import ma…

管理类联考——英语二——知识篇——写作题目说明——B节

MBA&#xff0c;MPA&#xff0c;MPAcc管理类联考英语写作部分由A&#xff0c;B两节组成&#xff0c;主要考查考生的书面表达能力。共2题&#xff0c;25分。A节要求考生根据所给情景写出约100词(标点符号不计算在内)的应用文&#xff0c;包括私人和公务信函、通知、备忘录等。共…

【ESP8266 (12F)】硬件参数 以及 固件烧录

本文资料及工具地址&#xff1a;https://github.com/CQUPTLei/ESP8266 一、基本关系1.1 ESP8266 芯片 和 ESP 12F 模组1.2 乐鑫科技和安信可 二、ESP 8266开发板2.1 ESP 12F 产品规格2.2 ESP8266 开发板 三、固件与固件下载3.1 什么是固件3.2 固件和用户程序3.2 如何下载固件3.…

Linux下配置lunavim

前言 在lunavim官网中提供了安装脚本&#xff0c;一件安装即可&#xff0c;但是经常因为网络不稳定而导致安装失败。这里提供在Linux下进行git加速的几种方法&#xff0c;可以尝试下。如果问题没有解决&#xff0c;也不要担心&#xff0c;我们还提供了两种平替方法进行luanvim的…

linux实验五sed和awk

按要求写出正则表达式 显示/etc/passwd中以bash结尾的行;显示/var/log/secure文件中包含“Failed”或“FAILED”的行查找/etc/man_db.conf中含有“以m开头&#xff0c;并以n结尾的单词”模式的行&#xff1b;显示/etc/man_db.conf中&#xff0c;包含Linux绝对路径的行&#xff…

基础巩固(六)自定义View

文章目录 View绘制流程MeasureLayoutDraw 自定义View的实现的步骤步骤1&#xff1a;实现Measure、Layout、Draw流程自定义 MeasureViewGroup.LayoutParamsMeasureSpec 自定义Layout 自定义属性 绘制工具类Paint具体使用 PathCanvas View绘制流程 在绘制前&#xff0c;系统会有一…

Python恶搞代码

文章目录 前言Tkinter界面设计Threading多线程恶搞代码 尾声 前言 快来领取python无限弹窗恶搞代码吧&#xff01;每天写一些有趣的小程序&#xff0c;带你成为一个浪漫的程序员&#xff01; Tkinter界面设计 1. 创建一个简单的界面 Tkinter 是 Python 标准库中的一个 GUI&…

自然语言处理从入门到应用——动态词向量预训练:双向语言模型

分类目录&#xff1a;《自然语言处理从入门到应用》总目录 对于给定的一段输入文本 w 1 w 2 ⋯ w n w_1w_2\cdots w_n w1​w2​⋯wn​&#xff0c;双向语言模型从前向&#xff08;从左到右&#xff09;和后向&#xff08;从右到左&#xff09;两个方向同时建立语言模型。这样做…

go 调试利器之pprof指标分析

文章目录 概要一、指标类型1.1、堆栈指标1.2、CPU指标分析1.3、http-pprof 二、go tool pprof2.1、可视化2.2、CPU火焰图 概要 Go语言原生支持对于程序运行时重要指标或特征进行分析。pprof是其中一种重要的工具&#xff0c;其不仅可以分析程序运行时的错误&#xff08;内存泄…

ChatGPT 之 LangChain的文本切割方法对比

本文来自http://blog.csdn.net/hellogv/ &#xff0c;引用必须注明出处&#xff01; ChatGPT面向对话格式的文本理解很好&#xff0c;但如果要把网络上的文章让ChatGPT直接分析则会有格式的问题。文本清洗是个大课题&#xff0c;讲起来需要很多篇幅&#xff0c;优化起来前路漫…

使用arduino IDE开发ESP8266NodeMCU连接DHT11实现温湿度检测并上传onenet官网

前言&#xff1a; 本篇博客记录一下以arduino IDE来开发一下ESP8266NodeMCU&#xff0c;实现用DHT11进行温湿度检测&#xff0c;并且上传新版的onenet官网&#xff1b;我在实现这个小项目的时候&#xff0c;发现网上资料有关onenet的资料都是旧版的&#xff0c;这就有点难受了&…

[MAUI]弧形进度条与弧形滑块的交互实现

文章目录 弧形基类定义绘制弧 弧形进度条(ProgressBar)添加动画宽度补偿文本 弧形滑块(Slider)创建控制柄拖动事件处理 项目地址 进度条&#xff08;ProgressBar&#xff09;用于展示任务的进度&#xff0c;告知用户当前状态和预期&#xff1b; 滑块&#xff08;Slider&#xf…

本地安装部署运行 ChatGLM-6B 的常见问题解答以及后续优化

报错 No module named ‘transformers_modules.THUDM/chatglm-6b’ 报错本身的意思是&#xff0c;没有在指定的路径THUDM/chatglm-6b找到推理用模型 一般常见于自己手动下载模型&#xff0c;而不是通过下边这些文件直接启动&#xff0c;自动下载的情况 你需要修改web_demo.py&…

分层测试终究是大梦一场空?

分层测试分了个寂寞&#xff1f; 分层测试这个风吹了好多年&#xff0c;不分层都不好意思说自己是专业测试。各互联网公司更是对此乐此不疲&#xff0c;测试架构、测试平台&#xff0c;搞了一套又一套&#xff0c;然而。。。 理想总是丰满&#xff0c;现实总是骨干&#xff0…