首页 > 其他分享 >路由跳转、相关api、路由守卫、路由两种工作模式

路由跳转、相关api、路由守卫、路由两种工作模式

时间:2024-05-06 16:22:18浏览次数:10  
标签:about name api 跳转 push router 路由

【router基本使用(路由跳转,携带数据)】

####### 跳转 #######
    -js跳转
        this.$router.push(路径)
        this.$router.push(对象)
            -this.$router.push({name:'路由别名'})
            -this.$router.push({path:'路径'})
        
    -组件跳转
        <router-link to="/about">
        <router-link :to="{name:'路由别名'}">
        <router-link :to="{path:'路径'}">
        
        
##### 路由跳转,携带数据############
    -请求地址中以  ? 形式携带 ---》 /about?name=数据
        #####router-link######
        -router-link 组件携带
            - to="/about?name=xxx"
              - :to="{name:'about',query:{name:'xxx',age:18}}"
        -在另一个页面组件中取:
            this.$route.query
        #####js跳转######
        -js跳转 携带数据
            -this.$router.push('/about?name=xxx&age=18')
            -this.$router.push({name: 'about', query: {name: 'xxx', age: 28}})
        -在另一个页面组件中取:
            this.$route.query
        

 

 1 <template>
 2   <div class="home">
 3     <h1>Home</h1>
 4     <!--    <<h></h>outer-link to="/about?name=xxx"><button>跳转到about</button></router-link>-->
 5     <!--    请求地址中以 ?形式携带-->
 6     <!--<router-link :to="{name:'about',query:{name:'xxx',age:18}}"><button>跳转到about</button></router-link>-->
 7     <hr>
 8     <button @click="handleTo">js跳转到about</button>
 9   </div>
10 
11 </template>
12 
13 <script>
14 
15 export default {
16   name: 'HomeView',
17   methods: {
18     handleTo() {
19       //1.js携带数据
20       // this.$router.push('/about?name=xxx&age=18')
21 
22       //2.js携带数据
23       this.$router.push({name: 'about', query: {name: 'xxx', age: 28}})
24     }
25   }
26 }
27 </script>

aboutView

<template>
  <div class="about">
    <h1>about页面</h1>

  </div>
</template>

<script>
export default {
  name: 'AboutView',
  data() {
    return {
      name: '',
    }
  },
  created() {
    console.log('$route', this.$route) //$route是当前路由信息对象
    //取值
    this.name = this.$route.query.name
  }
}
</script>

----------------------------------------------------------------------------

     
    -请求地址中携带 --》/about/数据/
        -必须在路由中写
              {
                path: '/about/:id/detail',
                name: 'about',
                component: AboutView
              },
           -标签跳转
            -to="/about/88"
            -:to="{name:'about',params:{id:66}}"
        -js跳转
            this.$router.push('/about/tt')
              this.$router.push({name: 'about', params: {id: 'xxx'}})
        -另一组件中取
            this.$route.params

【相关api】

1 指的是:this.$router--->方法

2 常用的 this.$router.push(path): 相当于点击路由链接(可以返回到当前路由界面)

this.$router.replace(path): 用新路由替换当前路由(不可以返回到当前路由界面)

this.$router.back(): 请求(返回)上一个记录路由

this.$router.go(-1): 请求(返回)上一个记录路由

this.$router.go(1): 请求下一个记录路由

【多级路由】

 

 

 1 <template>
 2   <div class="home">
 3 
 4   <div class="left">
 5     <router-link to="/backend/index"><p>首页</p></router-link>
 6     <router-link to="/backend/order"><p>订单页面</p></router-link>
 7     <router-link to="/backend/goods"><p>商品页面</p></router-link>
 8 
 9   </div>
10   <div class="right">
11     <router-view></router-view>
12   </div>
13   </div>
14 
15 </template>
16 
17 <script>
18 
19 export default {
20   name: 'HomeView',
21   methods: {
22 
23   },
24 
25 }
26 </script>
27 
28 <style scoped>
29 .home{
30   display: flex;
31 }
32 .left{
33   height: 300px;
34   width: 20%;
35   background-color: #42b983;
36 }
37 .right{
38   height: 300px;
39   width: 80%;
40   background-color: aqua;
41 }
42 </style>

 

【路由守卫】

 

 

 

 。

【路由两种工作模式】

# 1 对于一个url来说,什么是hash值?—— # 及其后面的内容就是hash值。

# 2 hash值不会包含在 HTTP 请求中,即:hash值不会带给服务器。

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

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

标签:about,name,api,跳转,push,router,路由
From: https://www.cnblogs.com/liuliu1/p/18175244

相关文章

  • 通过API触发airflow的DAG任务
    背景以前编写的DAG都是通过定时触发的,当前有一个场景需要通过手动提交API来触发,这样能够在用户需要的时候,主动触发执行任务,于是就有了这篇内容的摸索。之前只知道airflow支持通过API来触发任务,但是具体如何操作是真不会,看了官方的API文档,也没找到具体方法,特别是认证这块一直没解......
  • [西湖论剑 2022]easy_api
    源码审计下载附件得war包,bandzip解压一下,审一下源码:这个没啥东西。反序列化入口,但是访问这里是需要绕过的:其实绕过也很简单,双斜杠就绕了:web.xmlfilter绕过匹配访问(针对jetty)_jetty权限绕过-CSDN博客看lib里有啥依赖:fastjson1.2.48,这不老熟人了吗..... EXPfastjso......
  • 23 Alertmanager抑制、静默、路由、告警分组
    一、抑制机制Alertmanager的抑制机制可以避免当某种问题告警产生之后用户接收到大量由此问题导致的一系列的其它告警通知。例如当集群不可用时,用户可能只希望接收到一条告警,告诉他这时候集群出现了问题,而不是大量的如集群中的应用异常、中间件服务异常的告警通知。在Alertman......
  • 【详细教程】手把手教你开通YouTube官方API接口(youtube data api v3)
    一、背景调查1.1youtube介绍众所周知,youtube是目前全球最大的视频社交平台,该平台每天产生大量的视频内容,涵盖各种主题和类型,从音乐视频到教育内容,再到娱乐节目和新闻报道等。YouTube的用户群体也非常广泛,包括了各个年龄段、地区和兴趣爱好的人群。由于其庞大的用户基数和丰富的......
  • Camunda 整合SpringBoot基本Api
    代码实现:需要接口@AutowiredprivateRuntimeServiceruntimeService;@AutowiredprivateRepositoryServicerepositoryService;@AutowiredprivateTaskServicetaskService;发布流程:@GetMapping("/deploy")publicObjectdeploy(){......
  • Direct3D 11(D3D11)是Microsoft DirectX API 中的一部分,Direct3D 12(D3D12)是微软开发的一
    Direct3D11编程指南-Win32apps|MicrosoftLearn什么是Direct3D12-Win32apps|MicrosoftLearnDirect3D12编程指南-Win32apps|MicrosoftLearn你可以使用以下命令来查询系统是否支持D3D12:CopyCodedxdiag运行此命令将打开DirectX诊断工具,你可以在其中......
  • ollama + ollama web + fastapi app (langchain) demo
    ollama+ollamaweb+fastapiapp(langchain)demohttps://github.com/fanqingsong/ollama-dockerWelcometotheOllamaDockerComposeSetup!ThisprojectsimplifiesthedeploymentofOllamausingDockerCompose,makingiteasytorunOllamawithallitsd......
  • 网址链接跳转外部安全提醒代码
    网页的安全性优化是一个越来越被开发者重视的问题,当本站链接点击跳转到第三方外链接时,要弹框提示信息,需要支持jquery引用。<!DOCTYPE html>        <html>        <head>            <meta http-equiv="Content-Type" content="text/html......
  • View Transitions API 使用
    ViewTransitionsAPI提供了一种机制,可以在更新DOM内容的同时,轻松地创建不同DOM状态之间的动画过渡,这是官方对他的描述,详情请看这里。下方创建好了<!DOCTYPEhtml><htmllang="en"><head><metacharset="UTF-8"><metaname="viewport"content="......
  • eBPF基于LPM实现路由匹配
    基于eBPFlpmmap,icmp只有匹配上路由才能通。最终目录结构效果展示启动应用前,可以ping通192.168.0.1和192.168.0.105。启动应用后,无法ping通192.168.0.1,可以ping通192.168.0.105。停止应用后,可以ping通192.168.0.1和192.168.0.105。icmp/drop-icmp.c#include"../heade......