路由配置项:
       import Router from ‘vue-router’
       
                 1、path:路径
                 2、component:路径正确时显示的组件
                 
       重定向:path    redirect 访问根目录的时候,匹配的路径
                          
       匹配所有,在最后,(路径不对时),path:‘**’   component:Home
                 学习地址:vue官网,vue router   https://router.vuejs.org/zh/
       路由跳转:
                 1、<a href="#/home">           不推荐
                 2、<router-link to="/home">  比a标签多一个router-link-active 的class属性
                 3、编程式导航:this.$router.push()
                 
                          
       路由嵌套:(尽量不要嵌套超过3层)
                 页面的子页面  出现详情页
                 index.js 中导入,在要嵌套的页面路径导入 children [] 里面的path不加/ ,
       命名路由:(6个)
                 path
                 component
                 children  如: children:[ { },{ }]  ,{ }里面写路由的参数
                 name : 路由的名字
                          解决当path路径太长的情况
                          将path换为name,如
                          footer 中 <router-link :to="{name:item.name}">
                          home 二级嵌套中 <router-link :to="{name:'homedetails'}">
                 redirect 重定向  如;redirect:'/home'
                 
       
       路由传值:find页面
                 根据不同路径返回不同页面,页面间传值,显示不同的组件
                 组件传值是组件之间有依赖
                 1、params  
                          在路由path中添加属性
                          path:'/details/:name/:id'  需提前定义!!!
                          find中 :
                          to="'/detail/' + item + '/'+ index"   (无大括号!!!)
                                    接收用this.$route.params
                                    当不传值时,路径匹配不上,path为** 返回首页
                          <router-link :to="{name:'homedetails',params:{ name:item,id:index}}">
                                    接收用
                        信息比较重要的时候使用,一般都用parms,的后一种方法!
                 2、query (最轻松)
                          path中不需要提前定义 path:'/details'
                          <router-link :to="{name:'homedetails,query:{ name:item,id:index}'}">
                                    接收用this.$route.query
                          
                 
                 3、路由解耦
                          当使用parms传值的时候,可以再路由的配置项中添加一个属性props:true,这样在接收路由参数的组件中,用props( props:['name','id'] )直接接收数据,而不用this.$router
                          原因:query传值中属性key值 name,id 等可以随意更换不固定,而params中name,id是固定的,所以路由解耦用parms
                 4、编程式导航,
                          传值时,传过来的值在$route 中
                          导航时,方法都在this.$router 中
                                    push 是跳转  详见下面
                                    back 是返回  this.$router.back() 即可
                                    forward 前进 ??
                                    replace 替换所有当前路径(前进后退不能使用,因为之前的记录全部销毁),需要参数,如:this.$router.replace('/find')
                                    go()
                                    -1 后退 ; 0 刷新 ; 1 前进 ; (均表示页数)                
                          
                          li循环,添加@click,methods中调用方法,方法内容为
                          //如果params传值,不能使用path,用name 传值
                          this.$router.push({ name:'details',params:{ name:item,id:index } })
                          //如果用query传值,path 和 name 均可。注意index.js 中的路径
                          this.$router.push({ path:'details',params:{ name:item,id:index } })
                                                       path 后加 / 吗???
                          this.$router.push({ name:'details',params:{ name:item,id:index } })

vue中的路由的更多相关文章

  1. vue中的路由的跳转的参数

    vue中的路由跳转传参 params 与 query this.$router.push({ name:"detail", params:{ name:'nameValue', c ...

  2. vue中的路由独享守卫的理解

    1.vue中路由独享守卫意思就是对这个路由有一个单独的守卫,因为他的守卫方式于其他的凡是不太同 独享守卫于前置守卫使用方法大致是一样的 在路由配置的时候进行配置, { path:'/login', c ...

  3. vue 中的路由为什么 采用 hash 路由模式,而不是href超链接模式(Hypertext,Reference)?

    1. vue中路由模式的种类有两种 1. 一种是 hash 模式. 2. 一种是 h5 的 history 模式. 2. hash 和 history 都是来自 bom 对象 bom 来自 windo ...

  4. Vue中的路由 以及默认路由跳转

    https://router.vuejs.org/ vue路由配置: 1.安装 npm install vue-router --save / cnpm install vue-router --sa ...

  5. 5分钟学会vue中的路由守卫(导航守卫)

    在项目开发中每一次路由的切换或者页面的刷新都需要判断用户是否已经登录,前端可以判断,后端也会进行判断的,我们前端最好也进行判断. vue-router提供了导航钩子:全局前置导航钩子 beforeEa ...

  6. VUE中嵌套路由

    官网地址:https://router.vuejs.org/zh-cn/essentials/nested-routes.html 路由嵌套一般使用在后台管理系统中 给一个比较简单的小案例 <! ...

  7. vue中通过路由跳转的三种方式

    原文:https://blog.csdn.net/qq_40072782/article/details/82533477 router-view 实现路由内容的地方,引入组件时写到需要引入的地方需要 ...

  8. Vue中解决路由切换,页面不更新的实用方法

    前言:vue-router的切换不同于传统的页面的切换.路由之间的切换,其实就是组件之间的切换,不是真正的页面切换.这也会导致一个问题,就是引用相同组件的时候,会导致该组件无法更新,也就是我们口中的页 ...

  9. vue中的路由传参及跨组件传参

    路由跳转   this.$router.push('/course'); this.$router.push({name: course}); this.$router.go(-1); this.$r ...

随机推荐

  1. iOS 小米推送总结和遇到的坑

    极光推送就不赘述了,这里说下小米推送在ios上的坑吧,查了好久也没有查到相关的文章. 极光的强大就不说了,当客户贪图实惠的时候,当人家给你让你用小米推送的时候,我的内心是崩溃的,小米推送???没听过! ...

  2. 8小时入门Git之团队合作学习记录

    Git几个重要的区域 工作流程

  3. Javascript在使用import 与export 区别及使用

    一.import与export的用法 1.import的几种用法 import defautName from 'modules.js'; import { export } from 'module ...

  4. PWM_MOTOR_B

    port_cfg.h witti: #define PORT_CONFIG_PIN_E0_USAGE                        PORT_CONFIG_GPIO_OUT magna ...

  5. JSON.parse(JSON.stringify(obj))

    JSON.parse(JSON.stringify(obj)实现数组的深拷贝 利用JSON.stringify 将js对象序列化(JSON字符串),再使用JSON.parse来反序列化(还原)js对象

  6. Pandas逐行读取Dateframe并转为list

    for indexs in df.index: rowData = df.loc[indexs].values[0:7] rowData = rowData.tolist() #print(rowDa ...

  7. 不校验csrf

    from django.views.decorators.csrf import csrf_exempt@csrf_exemptdef a(request): pass

  8. 开发过程中 的一些 补充知识点 + 关于mysql中的日期和时间函数?

    参考: https://www.jb51.net/article/23966.htm https://yq.aliyun.com/articles/260389 mysql中的 日期格式是: HHHH ...

  9. combineReducers

    const reactInit = '@@react/Init' const combineReducers = (reducers) => { const finalReducers = {} ...

  10. [ZOJ 4020] Traffic Light

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=4020 很简单的一个bfs题,是我想多了. 顺便学习一下C++的S ...