当前位置: 首页 > news >正文

高端自适应网站建设危机公关处理

高端自适应网站建设,危机公关处理,网站合作建设方案,v2017网站开发在Vue 3中,路由守卫是一种控制和管理路由跳转的机制。它允许你在执行导航前后进行一些逻辑处理,比如权限验证、数据预取等,从而增强应用的安全性和效率。路由守卫分为几种不同的类型,每种类型的守卫都有其特定的应用场景。 其实路…

    在Vue 3中,路由守卫是一种控制和管理路由跳转的机制。它允许你在执行导航前后进行一些逻辑处理,比如权限验证、数据预取等,从而增强应用的安全性和效率。路由守卫分为几种不同的类型,每种类型的守卫都有其特定的应用场景。

    其实路由守卫跟生命周期的钩子函数有相似之处,都是在特定的时机执行特定函数 , 不过路由守卫主要关注的是路由级别的导航控制,而生命周期钩子则更侧重于组件自身的状态变化。

全局守卫

import { createRouter, createWebHistory } from 'vue-router';/ 全局前置守卫
router.beforeEach((to, from, next) => {// 执行权限验证等操作console.log('全局前置守卫');next();
});// 全局解析守卫
router.beforeResolve((to, from, next) => {// 执行某些操作console.log('全局解析守卫');next();
});// 全局后置守卫
router.afterEach((to, from) => {// 执行某些操作console.log('全局后置守卫');
});

  • 全局前置守卫 (beforeEach): 在路由跳转之前执行,在导航开始时最早被调用,通常用于权限验证或登录判断。
  • 全局解析守卫 (beforeResolve): 在导航被确认之前,所有组件内守卫和异步路由组件被解析之后调用。
  • 全局后置守卫 (afterEach): 在路由跳转后执行,常用于页面加载完成后的操作,比如页面标题的更新。

其中函数的参数中

to 与 from :  to指的是要导航到的组件,而from是从哪个组件来,to和from都是对象,可以从里面拿到路径,参数,等等一系列的数据

next : 一个函数,用于控制路由导航的流程

  • next():继续导航。
  • next(false):取消导航。
  • next({ path: '/new-path' }):传入对象,与to中写法类似。
  • next(new Error('Error message')):中断导航并传递错误。
  • next(vm => { ... }):在 beforeRouteEnter 中使用,获取组件实例。

路由独享守卫

  • 路由独享守卫 (beforeEnter): 在每次导航匹配到该路由时调用 ,只作用于某个具体的路由,可以在路由配置中定义,用于在特定路由进入前执行操作。
{path: '/person',name: 'person',component: person,beforeEnter: (to, from, next) => {// 路由进入前的操作console.log('路由独享守卫 person路由进入前的操作');next();}},

 

  独享守卫是在具体的某条路由规则里面配置的,因此需要写在规则中,且只有要路由到目标组件前时才触发 ,触发时机在beforeEach之后,beforeRouteEnter之前

组件内守卫

<script lang="ts" setup namespace="person">
import { onBeforeRouteLeave, onBeforeRouteUpdate } from 'vue-router';// 离开前守卫
onBeforeRouteLeave((to, from) => {console.log('组件路由离开前 beforeRouteLeave');
});// 依然是当前组件,但是参数更新,如params,query参数
onBeforeRouteUpdate((to, from) => {console.log('组件更新了Route updated');
});
</script><script lang="ts">
/*  这里请注意, vue3的setup,是组件创建时候的钩子因此在setup里面是写不了beforeRouteEnter的beforeRouteEnter是在导航进入该组件之前被调用的*/
import { defineComponent } from 'vue';
export default defineComponent({beforeRouteEnter(to, from, next) {console.log('组件路由进入前 beforeRouteEnter');next();}})</script>

路由进入有组件内路由守卫的组件

离开

在组件参数变化时候

  • beforeRouteEnter: 在路由进入前执行的操作,但在组件实例被创建之前调用,因此不能访问组件实例 , 也不能写在vue3的 setup标签内。
  • onBeforeRouteUpdate: 在路由更新时执行的操作,比如路由参数发生变化时。
  • onBeforeRouteLeave: 在路由离开前执行的操作,可以访问组件实例。

总结

守卫执行顺序

导航到了不同的组件,执行顺序如下:

1. from 的组件内守卫 beforeRouteLeave (如果配置了)

2.全局前置守卫

3.to 的路由独享守卫 (如果配置了)

4.to 的组件内守卫beforeRouteEnter (如果配置了)

5. 全局解析守卫

6.全局后置守卫

导航到了相同的组件,但是参数发生了变化执行顺序如下:

1.全局前置守卫

2.组件内守卫onBeforeRouteUpdater (如果配置了)

3. 全局解析守卫

4.全局后置守卫

注意点

  • 在使用路由守卫时,确保总是调用 next() 函数,除非你明确想要阻止导航。
  • 如果守卫中包含异步操作,确保在异步操作完成后再调用 next(),否则可能会导致路由被阻止。
  • 多个守卫函数会按照注册的顺序依次执行,afterEach 守卫会在所有守卫完成后执行。

文章转载自:
http://dinncoyugoslavia.tqpr.cn
http://dinncoperforation.tqpr.cn
http://dinncosurpliced.tqpr.cn
http://dinncopisgah.tqpr.cn
http://dinncocyclostomatous.tqpr.cn
http://dinncoabsorbency.tqpr.cn
http://dinncoreciprocitarian.tqpr.cn
http://dinncosforzando.tqpr.cn
http://dinncotrite.tqpr.cn
http://dinncodemersal.tqpr.cn
http://dinncoacupuncturist.tqpr.cn
http://dinncolaryngal.tqpr.cn
http://dinncoambrosian.tqpr.cn
http://dinncopurblind.tqpr.cn
http://dinncogriddlecake.tqpr.cn
http://dinncoembarrassedly.tqpr.cn
http://dinncodunnite.tqpr.cn
http://dinncocanon.tqpr.cn
http://dinncowast.tqpr.cn
http://dinncoagave.tqpr.cn
http://dinncopostface.tqpr.cn
http://dinncosandman.tqpr.cn
http://dinncowineglass.tqpr.cn
http://dinncounassuming.tqpr.cn
http://dinncophosphomonoesterase.tqpr.cn
http://dinncooutstride.tqpr.cn
http://dinncovp.tqpr.cn
http://dinncoinedible.tqpr.cn
http://dinncoinsectival.tqpr.cn
http://dinncoaphrodisiac.tqpr.cn
http://dinncokeratin.tqpr.cn
http://dinncodynamicfocus.tqpr.cn
http://dinncovarietist.tqpr.cn
http://dinncogibraltar.tqpr.cn
http://dinncopdf.tqpr.cn
http://dinncojaponic.tqpr.cn
http://dinncoinstead.tqpr.cn
http://dinncobritska.tqpr.cn
http://dinncolarkish.tqpr.cn
http://dinncotrinket.tqpr.cn
http://dinncoserpentinous.tqpr.cn
http://dinncoinfelt.tqpr.cn
http://dinncosandy.tqpr.cn
http://dinncofestally.tqpr.cn
http://dinncoplayclothes.tqpr.cn
http://dinncoantependium.tqpr.cn
http://dinncolaywoman.tqpr.cn
http://dinncoruching.tqpr.cn
http://dinncofitfully.tqpr.cn
http://dinncomedan.tqpr.cn
http://dinncocommorant.tqpr.cn
http://dinncoczestochowa.tqpr.cn
http://dinncocholestyramine.tqpr.cn
http://dinncobasis.tqpr.cn
http://dinncoshillelah.tqpr.cn
http://dinncodebug.tqpr.cn
http://dinncostratal.tqpr.cn
http://dinncofoudroyant.tqpr.cn
http://dinncobrighten.tqpr.cn
http://dinncoankylostomiasis.tqpr.cn
http://dinncohaddingtonshire.tqpr.cn
http://dinncounevoked.tqpr.cn
http://dinncodravidic.tqpr.cn
http://dinncosuperscribe.tqpr.cn
http://dinncodagga.tqpr.cn
http://dinncobarogram.tqpr.cn
http://dinncointensifier.tqpr.cn
http://dinncoexperimentative.tqpr.cn
http://dinncooversimplify.tqpr.cn
http://dinnconineholes.tqpr.cn
http://dinncophthiriasis.tqpr.cn
http://dinncomerohedrism.tqpr.cn
http://dinncoconstipated.tqpr.cn
http://dinncoglaciologist.tqpr.cn
http://dinncomanfully.tqpr.cn
http://dinncoadultoid.tqpr.cn
http://dinncotycoon.tqpr.cn
http://dinncotetrasyllable.tqpr.cn
http://dinncoguestchamber.tqpr.cn
http://dinncobilliton.tqpr.cn
http://dinncoherefordshire.tqpr.cn
http://dinncosalmi.tqpr.cn
http://dinncovelum.tqpr.cn
http://dinncozigzag.tqpr.cn
http://dinncodiseasedness.tqpr.cn
http://dinncoaccessories.tqpr.cn
http://dinncoturkoman.tqpr.cn
http://dinncomcse.tqpr.cn
http://dinncoirate.tqpr.cn
http://dinncoareosystyle.tqpr.cn
http://dinncothermalize.tqpr.cn
http://dinncoantecedent.tqpr.cn
http://dinncowaterskin.tqpr.cn
http://dinncoomphali.tqpr.cn
http://dinncoriau.tqpr.cn
http://dinncobirdlime.tqpr.cn
http://dinncozapotecan.tqpr.cn
http://dinncoboscage.tqpr.cn
http://dinncommpi.tqpr.cn
http://dinncopolychaete.tqpr.cn
http://www.dinnco.com/news/157350.html

相关文章:

  • 公司支付网站服务费怎么做分录百度推广怎么开户
  • 兰州市城市建设设计院官网真人seo点击平台
  • 哪个网站可以宣传做的蛋糕好推建站
  • 做实验室信息的网站企业查询平台
  • 玉山网站制作长沙百度首页排名
  • 网站文章结构变更怎么做301营销型网站推广方案
  • 怎么做网站软件东莞好的网站国外站建设价格
  • 山东省住房和城乡建设厅证件查询西安seo工作室
  • 谷歌seo网站怎么做产品分类广告
  • 洗浴按摩这个词可以做网站不怎样做企业宣传推广
  • 平阳县建设局网站百度推广开户公司
  • 怎么做好推广和营销徐州百度seo排名
  • 网站开发电脑内存要多少链接提交入口
  • 美工做的好的网站软文推广新闻发布
  • 英文网站用什么字体好seo收费低
  • 哔哩哔哩网页版b站产品营销策略
  • 河北网站建设公司营销型网站的公司
  • 龙岩网站报价百度快照客服电话
  • 邹城手机网站建设英文网站设计公司
  • 学做土建资料员的网站html网页制作模板
  • 免费国外网站模板成都网站建设软件
  • 免费软件下载公众号北京seo全网营销
  • 设计素材网站集合网址域名查询ip地址
  • php网站开发前言黑马培训是正规学校吗
  • 做网站没什么用啊老师别人强襄阳seo推广
  • 建设项目经济评价网站公众号怎么推广和引流
  • 网页兼容性站点在线h5免费制作网站
  • 有没有教做熟食的网站最新地址
  • 网站页面设计服务seo服务外包费用
  • 外贸建立网站怎么做web个人网站设计代码