vue-router 配置、跳转与传参
2019-06-04 16:55
183 查看
版权声明:本文为博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/qq_43574304/article/details/90778856
vue-router 配置、跳转与传参
一、配置
路由的配置属性书要有:path,name,component,redirect
基本配置: {path:/,name:index,component:index} 路由重定向: {path:'/'redirect:'/index'} 配置 mode:“history” 表示浏览器地址不需要 hash,即不显示 ’/#‘
二、跳转
主要有两种跳转方式
1.router-link标签的方式利用to属性进行跳转
<router-link v-for='(item,index) in table' :to="item.index">{{item.name}}</router-link>
2.事件跳转(this.$router.push)
<div @click="changeTab(item,index)" v-for="(item,index) in table"> {{item.name}} </div> methods:{ changeTab(item,index){ this.$router.push(name:item.index) }, arrayDemo(){ } },
三、传参
1.通过router-link标签传参
<router-link v-for='(item,index) in table' :to="{path:item.index,query:{id:item.id}}">{{item.name}}</router-link> <router-link v-for='(item,index) in table' :to="{name:item.index,params:{id:item.id}}">{{item.name}}</router-link>
2.通过事件跳转时传值
methods:{s changeTab(item,index){ this.$router.push({name:item.index,params:{id:item.id}}) this.$router.push({path:item.index,query:{id:item.id}}) }, arrayDemo(){ } },
这里path和query对应传参的方式类似于get在地址栏可以看到,name和params对应传参的方式类似于post
获取参数的方式分别为:this.route.query和this.route.query和this.route.query和this.route.params
相关文章推荐
- 实战 Vue 第2天:了解 vue-router 路由配置、跳转与传参
- 实战 React 第2天:掌握 react-router-dom 路由配置、跳转与传参
- vue-router实现登录和跳转到指定页面,vue-router 传参
- vue中router-link传参(商品从列表页到具体详情页跳转)
- VUE使用router.push实现页面跳转和传参
- vue-router实现几级页面跳转及传参
- react-router HashRouter和BrowserHistory的区别, 以及配置、使用, Link跳转传参等等
- vue2.0子路由配置和跳转 vue-router: 嵌套路由
- vue-router--路由传参结合请求数据(页面底部按钮跳转功能实现参考)
- vue-router二级路由跳转一级路由传参(变量)的问题
- 关于react-router4中路由的配置,传参,跳转,可选参数写法
- vue基础教程(四) - 路由的配置、跳转、传参、嵌套
- vueJs+webpack单页面应用--vue-router配置
- Vue路由(vue-router)配置实战——动态路由,重定向,工程非根目录
- vue-cli 配置路由之间跳转传递参数
- 在vue中无论使用router-link 还是 @click事件,发现都没法从列表页点击跳转到内容页去
- vue-router+nginx 非根路径配置方法
- 解决vue-router中的query动态传参问题
- react-router-dom 函数跳转传参
- Vue的路由配置及手动改地址栏为啥又跳转回来??