页面跳转与传值
一、使用router-link
routes路由:
1 | export default new Router({ |
使用<router-link>
进行跳转和传值
1 | <router-link :to="{name:'deitail',params:{freezeMon:'2017-10',owerName:'西安'}}" tag="div" > |
取值时:
1 | <h1>{{$route.params.freezeMon}}</h1> |
小结:router-link跳转传值要注意的地方
- to前面要加
:
- to后面{中的name值要与路由中的name值一致
二、使用$router.push()
query写法
传值的路由
1 | this.$router.push({ |
传值路由第二种写法
1 | this.$router.push({ |
接收值的路由
1 | console.log("接收过来的值为:" + this.$route.query.uname); //这里是$route 没有r---- |
params写法
传值路由第一种写法(还是会将参数显示在地址栏中)
1 | this.$router.push({ |
传值路由的第二种写法(不会将参数显示在地址栏中)
1 | this.$router.push({ |
接收值的路由
1 | console.log("接收过来的值为:" + this.$route.params.uname); |
注意:在使用params传递参数的时候,我们需要在router的对象里面,找到当前的这个路由,然后去更改它的 path
1 | { |
上面的path后面是 /login/:uname ,这一个是我们的一个路径变量,前面的login代表路由,而后面:uname
代表的是变量